- . * - Date from EXIF "DateTimeOriginal" * - Max size 15MB per file * - Live Countdown & Progress Bar * - Modern Dark UI */ // EVENT CONFIGURATION const EVENT_NAME = 'Event Bilder Upload'; const EVENT_SUBTITLE = 'Speichere deine Momente datumsgerecht.'; // DEADLINE CONFIGURATION // Format: YYYY-MM-DD HH:MM:SS const UPLOAD_DEADLINE = '2026-11-30 23:59:59'; // Timezone date_default_timezone_set('Europe/Berlin'); $messages = []; // Array to store status messages for each file // Maximum file size in bytes (15 MB) const MAX_FILE_SIZE = 15 * 1024 * 1024; if ($_SERVER['REQUEST_METHOD'] === 'POST') { header('Content-Type: application/json'); $responseMessages = []; // Check Deadline if (time() > strtotime(UPLOAD_DEADLINE)) { echo json_encode([ 'status' => 'error', 'messages' => [['type' => 'error', 'text' => 'Der Upload-Zeitraum ist abgelaufen.']] ]); exit; } $targetDir = __DIR__ . "/images/"; // Ensure directory exists if (!is_dir($targetDir)) { if (!@mkdir($targetDir, 0755, true)) { $errorInfo = error_get_last(); $sysError = $errorInfo ? $errorInfo['message'] : 'Unbekannter Fehler'; echo json_encode([ 'status' => 'error', 'messages' => [['type' => 'error', 'text' => "Server-Fehler: Konnte Verzeichnis 'images' nicht erstellen. ($sysError)"]] ]); exit; } } if (isset($_FILES['images'])) { $fileCount = count($_FILES['images']['name']); $descriptions = $_POST['descriptions'] ?? []; for ($i = 0; $i < $fileCount; $i++) { $fileName = $_FILES['images']['name'][$i]; $fileTmpPath = $_FILES['images']['tmp_name'][$i]; $fileSize = $_FILES['images']['size'][$i]; $fileError = $_FILES['images']['error'][$i]; $description = trim($descriptions[$i] ?? ''); // Context prefix for messages $msgPrefix = "$fileName: "; // Validate Description $descriptionSafe = preg_replace('/[^a-zA-Z0-9\-_äöüÄÖÜß ]/u', '', $description); $descriptionSafe = trim(preg_replace('/\s+/', ' ', $descriptionSafe)); if (empty($descriptionSafe)) { $responseMessages[] = ['type' => 'error', 'text' => $msgPrefix . "Keine gültige Beschreibung."]; continue; } if ($fileError !== UPLOAD_ERR_OK) { $errorMessages = [ UPLOAD_ERR_INI_SIZE => 'Datei zu groß (server limit).', UPLOAD_ERR_FORM_SIZE => 'Datei zu groß (form limit).', UPLOAD_ERR_PARTIAL => 'Nur teilweise hochgeladen.', UPLOAD_ERR_NO_FILE => 'Keine Datei.', UPLOAD_ERR_NO_TMP_DIR => 'Temporärer Ordner fehlt.', UPLOAD_ERR_CANT_WRITE => 'Schreibfehler.', ]; $err = $errorMessages[$fileError] ?? "Fehler Code $fileError"; $responseMessages[] = ['type' => 'error', 'text' => $msgPrefix . $err]; continue; } if ($fileSize > MAX_FILE_SIZE) { $responseMessages[] = ['type' => 'error', 'text' => $msgPrefix . "Größer als 15MB."]; continue; } // Extension Check $fileNameCmps = explode(".", $fileName); $fileExtension = strtolower(end($fileNameCmps)); $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'heic']; if (!in_array($fileExtension, $allowedExtensions)) { $responseMessages[] = ['type' => 'error', 'text' => $msgPrefix . "Format nicht erlaubt."]; continue; } // Exif Date $dateStr = null; if (function_exists('exif_read_data')) { $exif = @exif_read_data($fileTmpPath); if ($exif && !empty($exif['DateTimeOriginal'])) { $dateTimeObj = DateTime::createFromFormat('Y:m:d H:i:s', $exif['DateTimeOriginal']); if ($dateTimeObj) { $dateStr = $dateTimeObj->format('d-m-Y'); } } } if (!$dateStr) { $dateStr = date('d-m-Y'); } // Construct Target Path $newFileName = "{$dateStr} - {$descriptionSafe}.{$fileExtension}"; $dest_path = $targetDir . $newFileName; // Handle Duplicates $counter = 1; $info = pathinfo($dest_path); while (file_exists($dest_path)) { $dest_path = $info['dirname'] . '/' . $info['filename'] . " ($counter)." . $info['extension']; $newFileName = basename($dest_path); $counter++; } if (move_uploaded_file($fileTmpPath, $dest_path)) { $responseMessages[] = ['type' => 'success', 'text' => $msgPrefix . "Gespeichert als \"$newFileName\"."]; } else { $errorInfo = error_get_last(); $sysError = $errorInfo ? $errorInfo['message'] : 'Unbekannter Fehler'; $responseMessages[] = ['type' => 'error', 'text' => $msgPrefix . "Upload gescheitert: $sysError"]; } } } echo json_encode(['status' => 'done', 'messages' => $responseMessages]); exit; } ?> <?= htmlspecialchars(EVENT_NAME) ?>

Lädt...
Dateien wählen oder per Drag & Drop (Max. 15MB/Bild)