commit b903cca6e23a6ac6f064847c971778667dcd9140 Author: DenisM Date: Wed May 20 23:32:01 2026 +0300 Да будет код... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2333d60 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/uploads \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..e288563 --- /dev/null +++ b/index.html @@ -0,0 +1,29 @@ + + + + + + + Document + + + + + + + + + \ No newline at end of file diff --git a/lib_chunk_file.js b/lib_chunk_file.js new file mode 100644 index 0000000..25575a1 --- /dev/null +++ b/lib_chunk_file.js @@ -0,0 +1,31 @@ + +// Размер чанка в байтах +const CHUNK_SIZE = 1024 * 1024; // 1MB + +async function uploadFileInChunks(file) { + + const totalChunks = Math.ceil(file.size / CHUNK_SIZE); + + for (let chunkIndex = 0; chunkIndex < totalChunks; chunkIndex++) { + + // Вычисляем начало и конец текущего чанка + const start = chunkIndex * CHUNK_SIZE; + const end = Math.min(start + CHUNK_SIZE, file.size); + + // Извлекаем чанк из файла + const chunk = file.slice(start, end); + + // Создаём FormData для отправки чанка + const formData = new FormData(); + formData.append('file_chunk', chunk); + formData.append('chunk_index', chunkIndex); + formData.append('total_chunks', totalChunks); + formData.append('filename', file.name); + + // Отправляем чанк на сервер + await fetch('upload.php', { + method: 'POST', + body: formData + }); + } +} \ No newline at end of file diff --git a/upload.php b/upload.php new file mode 100644 index 0000000..db5a394 --- /dev/null +++ b/upload.php @@ -0,0 +1,38 @@ + 'error', 'message' => 'Не удалось открыть временный файл'])); + } + + // Если это последняя часть, переименовываем файл в итоговый + if ($chunkIndex === $totalChunks - 1) { + $finalFilePath = $uploadDir . $originalFilename; + rename($tempFilePath, $finalFilePath); + echo json_encode(['status' => 'success', 'message' => 'Файл успешно собран', 'path' => $finalFilePath]); + } else { + echo json_encode(['status' => 'uploading', 'chunk' => $chunkIndex]); + } +} +?> \ No newline at end of file