diff --git a/upload.html b/upload.html index fc09bf2..3080e85 100644 --- a/upload.html +++ b/upload.html @@ -175,14 +175,7 @@

Lade dein eigenes PNG hoch. Es wird uns per E-Mail gesendet und wir binden es in deine App ein.

- -
- - - - - - +
@@ -209,10 +202,6 @@ - -
@@ -257,7 +246,6 @@ const imagePreview = document.getElementById('image-preview'); const submitBtn = document.getElementById('submit-btn'); const customerInfo = document.getElementById('customer-info'); - const emailInfo = document.getElementById('email-info'); // Drag and Drop Effects ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { @@ -308,7 +296,6 @@ previewBox.style.display = 'none'; submitBtn.style.display = 'none'; customerInfo.style.display = 'none'; - emailInfo.style.display = 'none'; valFormat.innerHTML = ` Überprüfe Dateiformat...`; valFormat.className = ''; @@ -342,7 +329,6 @@ previewBox.style.display = 'block'; customerInfo.style.display = 'block'; submitBtn.style.display = 'block'; - emailInfo.style.display = 'block'; } else { setValidationMsg(valResolution, false, '', `Fehler: Falsche Auflösung (${width}x${height}px). Erwartet: 1500x1000px.`); } @@ -354,6 +340,41 @@ }; reader.readAsDataURL(file); } + + const form = document.getElementById('bg-upload-form'); + form.addEventListener('submit', async (e) => { + e.preventDefault(); + + const formData = new FormData(form); + const originalBtnText = submitBtn.innerHTML; + submitBtn.innerHTML = ' Lade hoch...'; + submitBtn.disabled = true; + + try { + const response = await fetch('upload_backend.php', { + method: 'POST', + body: formData + }); + + const result = await response.json(); + + if (response.ok) { + alert('Erfolgreich hochgeladen!'); + form.reset(); + previewBox.style.display = 'none'; + submitBtn.style.display = 'none'; + customerInfo.style.display = 'none'; + validationBox.style.display = 'none'; + } else { + alert('Fehler: ' + (result.error || 'Unbekannter Fehler')); + } + } catch (error) { + alert('Upload fehlgeschlagen. Bitte prüfe deine Verbindung.'); + } finally { + submitBtn.innerHTML = originalBtnText; + submitBtn.disabled = false; + } + }); }); diff --git a/upload_backend.php b/upload_backend.php new file mode 100644 index 0000000..c1a33b6 --- /dev/null +++ b/upload_backend.php @@ -0,0 +1,76 @@ + 'Method not allowed']); + exit; +} + +$uploadDir = __DIR__ . '/uploads/'; +if (!is_dir($uploadDir)) { + // Attempt to create if not exists (though Docker should map it) + @mkdir($uploadDir, 0755, true); +} + +// Check if file is uploaded +if (!isset($_FILES['background_image']) || $_FILES['background_image']['error'] !== UPLOAD_ERR_OK) { + http_response_code(400); + echo json_encode(['error' => 'Keine Datei hochgeladen oder Ein Fehler ist aufgetreten.']); + exit; +} + +$file = $_FILES['background_image']; +$email = isset($_POST['email']) ? htmlspecialchars($_POST['email']) : 'Keine E-Mail angegeben'; + +// Validate file type +$finfo = finfo_open(FILEINFO_MIME_TYPE); +$mimeType = finfo_file($finfo, $file['tmp_name']); +finfo_close($finfo); + +if ($mimeType !== 'image/png') { + http_response_code(400); + echo json_encode(['error' => 'Nur PNG-Dateien sind erlaubt.']); + exit; +} + +// Generate unique filename +$filename = uniqid('frame_') . '_' . time() . '.png'; +$destination = $uploadDir . $filename; + +// Move uploaded file +if (move_uploaded_file($file['tmp_name'], $destination)) { + // Build public URL + // Assuming the app is accessible at https://schnappix.orfel.de + $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; + $host = $_SERVER['HTTP_HOST']; + $publicUrl = $protocol . '://' . $host . '/uploads/' . $filename; + + // Send notification to Ntfy + $ntfyUrl = 'https://ntfy.orfel.de/Schnappix-Frame-Upload'; + $message = "Ein neuer Rahmen wurde hochgeladen!\n\nVon: $email\nBild-URL: $publicUrl"; + + $ch = curl_init($ntfyUrl); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $message); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Title: Neuer Schnappix Hintergrund', + 'Tags: frame_with_picture,tada', + 'Click: ' . $publicUrl, + 'Attach: ' . $publicUrl + ]); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_exec($ch); + curl_close($ch); + + echo json_encode([ + 'success' => true, + 'message' => 'Datei erfolgreich hochgeladen.', + 'url' => $publicUrl + ]); +} else { + http_response_code(500); + echo json_encode(['error' => 'Fehler beim Speichern der Datei.']); +}