I am trying to integrate fine uploader [ Jquery wrapper ] for my PHP project. In that, i am trying to upload a 25MB file by using chunking option.
But what is happening here is, It chunks file and stores as blob0, blob1, blob2...
I want to my original file to be stored in the location. But here, the chunks get stored with a different name. What i have tired so far is,
<div id="jquery-wrapped-fine-uploader"></div>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.fineuploader-3.5.0.js"></script>
<script>
$(document).ready(function () {
$('#jquery-wrapped-fine-uploader').fineUploader({
debug: true,
request: {
endpoint: 'upload.php',
},
chunking: {
enabled: true,
partSize: 2000000,
paramNames: {
partIndex: 'qqpartindex',
partByteOffset: 'qqpartbyteoffset',
chunkSize: 'qqchunksize',
totalFileSize: 'qqtotalfilesize',
totalParts: 'qqtotalparts',
filename: 'qqfile'
}
}
});
});
</script>
PHP
if ($_FILES["qqfile"]["error"] > 0)
{
echo "Return Code: " . $_FILES["qqfile"]["error"] . "<br>";
} else {
$partIndex = $_POST["qqpartindex"];
$fileName = $_POST["qqfile"];
move_uploaded_file($_FILES["qqfile"]["tmp_name"], "data/" . $_FILES["qqfile"]["name"].$partIndex);
$result['success'] = true;
echo json_encode($result);
}
I don't know where i went wrong and what i have missed. Please someone guide me.
The point is, this is a feature of the fine uploader. The chunks are given as separate files so that in case your upload gets corrupted, you would have a way to compare and discard chunks that are invalid. If you wish to just get the file, what you need is the following:
if ($_FILES["qqfile"]["error"] > 0)
{
echo "Return Code: " . $_FILES["qqfile"]["error"] . "<br>";
} else {
$partIndex = $_POST["qqpartindex"];
$fileName = $_POST["qqfile"];
move_uploaded_file($_FILES["qqfile"]["tmp_name"], "data/" . $_FILES["qqfile"]["name"].$partIndex);
// INSERT CODE HERE TO CHECK THE INTEGRITY OF "data/" . $_FILES["qqfile"]["name"].$partIndex
$file = fopen($filename, 'a');
$content = file_get_contents("data/" . $_FILES["qqfile"]["name"].$partIndex);
if (fwrite($file, $content)) $result['success'] = true;
fclose($file);
echo json_encode($result);
}
, where $filename is the name of the file you are uploading. I would tell you how to get it through this code, but it's probably easier to define it upstream. Also, depending on your upstream code, it will probably be more memory-efficient to do the fopen at the beginning of the upload, and fclose at the end of your code (e.g.
$file = FALSE;
if ($partIndex == 0) $file = fopen("filename");
instead of the line $file = fopen($filename, 'a'); But, in this case you need to fclose($file); only at the end of the upload (or not at all, it will be fclosed once the page loads). But once again, without seeing the rest of your code I cannot know what will work best in this particular case.