($deleteAfterDays * 86400)) { @unlink($file); } } } /* ========================================================= Upload-Historie laden ========================================================= */ $history = []; if (file_exists($historyFile)) { $json = file_get_contents($historyFile); $history = json_decode($json, true) ?: []; } /* ========================================================= Chunk-Upload Verarbeitung (PHP Backend) ========================================================= */ if (isset($_FILES['upload']) && $_FILES['upload']['error'] === UPLOAD_ERR_OK) { $tmpFile = $_FILES['upload']['tmp_name']; $originalName = basename($_FILES['upload']['name']); $extension = strtolower(pathinfo($originalName, PATHINFO_EXTENSION)); // Dateityp prüfen if (!in_array($extension, $allowedExtensions)) { http_response_code(400); header('Content-Type: application/json'); echo json_encode(['error' => 'Dateityp nicht erlaubt']); exit; } $chunkIndex = (int) ($_POST['chunkIndex'] ?? 0); $totalChunks = (int) ($_POST['totalChunks'] ?? 1); $partialFile = $uploadDir . '/' . $originalName . '.part'; // Bei erstem Chunk → alte .part-Datei löschen if ($chunkIndex === 0 && file_exists($partialFile)) { @unlink($partialFile); } // Chunk anhängen file_put_contents($partialFile, file_get_contents($tmpFile), FILE_APPEND); // Letzter Chunk → Datei finalisieren if ($chunkIndex + 1 === $totalChunks) { // Eindeutigen Dateinamen finden (Dateiname (1).ext, Dateiname (2).ext, ...) $finalPath = $uploadDir . '/' . $originalName; $counter = 1; $baseName = pathinfo($originalName, PATHINFO_FILENAME); while (file_exists($finalPath)) { $finalPath = $uploadDir . '/' . $baseName . " ($counter)." . $extension; $counter++; } rename($partialFile, $finalPath); // Öffentliche Download-URL erstellen $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://'; $basePath = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'); $publicUrl = $protocol . $_SERVER['HTTP_HOST'] . $basePath . '/uploads/' . basename($finalPath); // In Historie speichern (neueste oben) array_unshift($history, [ 'name' => basename($finalPath), 'url' => $publicUrl, 'time' => time(), 'size' => filesize($finalPath) ]); // Maximal 20 Einträge behalten $history = array_slice($history, 0, 20); file_put_contents( $historyFile, json_encode($history, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) ); // Erfolgsmeldung an Frontend header('Content-Type: application/json'); echo json_encode([ 'success' => true, 'url' => $publicUrl, 'name' => basename($finalPath) ]); exit; } // Bei jedem Chunk außer dem letzten header('Content-Type: application/json'); echo json_encode(['success' => true]); exit; } ?> Datei Upload

Datei Upload

(Datei Einzelgröße bis 10 GB)

Dateien hierher ziehen oder klicken


Letzte Uploads