Yorum yapan herkese teşekkür ederim
Sorunu çözdüm arkadaşlar.
Chunk upload olayı ile.
Dosyayı 50 mb parçalara veya 2 mb parçalara bölüp
php ile sunucu tarafında kendisi birleştiriyor.
%100 ÇÖZDÜM
CHUNK UPLOAD OLAYI İLE
<script>
const chunkSize = 100 * 1024 * 1024; // 100 MB
function upload() {
const file = document.getElementById('fileInput').files[0];
if (!file) return alert("Dosya seçilmedi");
const totalChunks = Math.ceil(file.size / chunkSize);
let currentChunk = 0;
const uploadNextChunk = () => {
const start = currentChunk * chunkSize;
const end = Math.min(start + chunkSize, file.size);
const chunk = file.slice(start, end);
const formData = new FormData();
formData.append("chunk", chunk);
formData.append("name", file.name);
formData.append("chunkIndex", currentChunk);
formData.append("totalChunks", totalChunks);
const xhr = new XMLHttpRequest();
xhr.open("POST", "chunk_upload.php", true);
xhr.onload = function () {
if (xhr.status === 200) {
currentChunk++;
document.getElementById("status").innerText = `Yükleniyor: ${((currentChunk / totalChunks) * 100).toFixed(2)}%`;
if (currentChunk < totalChunks) {
uploadNextChunk();
} else {
document.getElementById("status").innerText = "✅ Yükleme tamamlandı.";
}
} else {
document.getElementById("status").innerText = "❌ Hata oluştu.";
}
};
xhr.send(formData);
};
uploadNextChunk();
}
</script>PHP DOSYASINA YAZILACAK KODLAR
<?php
$targetDir = __DIR__ . "/uploads/";
if (!is_dir($targetDir)) mkdir($targetDir, 0777, true);
$name = $_POST['name'];
$chunkIndex = intval($_POST['chunkIndex']);
$totalChunks = intval($_POST['totalChunks']);
$tempFile = $_FILES['chunk']['tmp_name'];
$targetFile = $targetDir . $name . ".part" . $chunkIndex;
move_uploaded_file($tempFile, $targetFile);
// Son parça yüklendiyse birleştir
if ($chunkIndex + 1 === $totalChunks) {
$finalFile = $targetDir . $name;
$output = fopen($finalFile, 'wb');
for ($i = 0; $i < $totalChunks; $i++) {
$part = $targetDir . $name . ".part" . $i;
$in = fopen($part, 'rb');
stream_copy_to_stream($in, $output);
fclose($in);
unlink($part);
}
fclose($output);
echo "✅ Dosya birleştirildi: " . $name;
} else {
echo "🧩 Parça {$chunkIndex} alındı.";
}@A.AY;
@Punisher;
@x0rz;
@delikurt55;
@cetin61;