I have implemented a library ( Dropzone.js ) to be able to upload Large files to my server from my application (it splits them into 5 Mb chunks) and it works perfectly.
If you wanted to download the file from the server . How do I fly to join the pieces with PHP?
(The uploaded file is not always a .rar , it can be any type of file)
I leave you the code used here.
index.php
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>test upload by chunk</title>
<link rel="stylesheet" href="components/dropzone.css">
<script type="text/javascript" src="components/dropzone.js">
</script>
</head>
<body>
<div class="control-group">
<form id="cuadro" class="dropzone">
</form>
</div>
<script>
var Dropzone = new Dropzone("#cuadro", {
url: "upload.php",
maxFilesize : 600,
chunking: true,
chunkSize: 5120000,
retryChunks: true,
retryChunksLimit: 3,
chunksUploaded: function(file, done) {
done();
}
});
</script>
</body>
</html>
and here I keep each fragment
upload.php
<?php
function generateRandomString($length = 5) {
return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}
if (!empty($_FILES)) {
try {
$nombre = generateRandomString();
$tempFile = $_FILES['file']['tmp_name']; //seleccionamos el nombre temporal del archivo
$ext = explode(".", $_FILES['file']['name']); // Buscamos la extension del archivo
$ext =end($ext);
$nombreCompleto = $nombre .'.'.$ext; //creamo un nombre para almacenar en la carpeta del servidor
$targetPath = "upload/"; //creamos la direccion donde se guardara el archivo
$targetFile = $targetPath. $nombreCompleto; //5
move_uploaded_file($tempFile,$targetFile); //6
} catch (Exception $e) {
echo "
<scrip>
console.log($e);
</script>
";
}
}
?>
I have solved the problem