As stated, I have a problem with the response if I upload multiple files at once. For example, I upload a.jpg
and b.jpg
. In the next step, I upload b.jpg
and c.jpg
. My PHP script checks the names for duplicity and finds one in b.jpg
but as response, I got each images flagged with
error - file already there.
I can't differ the responses individually.
I initialize my dropzone via jquery:
myDropZone = $("#dropzone").dropzone({
autoProcessQueue: false,
uploadMultiple: true,
xx: xx
init:function(){
var self = this;
// check error and some other states
self.on("error", function (file, response) {
console.log("error: "+file);
console.log("error-response: "+response);
}
// set process
$("#actions .start").click (function(file){
self.processQueue();
}
}
});
I use uploadMultiple
for multiple fileupload, I disabled the autoprocess
and binded the function processQueue()
to a button of my liking. So far so good.
No I have my php-script processing the data. It should be called once because of the uploadMultiple
parameter.
if (!empty($_FILES)) {
// resort array for easy processing
for($i = 0 ;$i < count($_FILES['file']['name']) ; $i++) {
$fileArrays[] = array_column ( $_FILES['file'], $i);
}
foreach($fileArrays as $file) {
$upload = array();
if(file_exists($file[0])) {
$upload[] = "File already there.";
}
// some other validations...
}
if(empty($upload)) {
//move_uploaded_file()
http_response_code(200);
} else {
print_r($upload);
http_response_code(404);
}
But now all uploads get all responses, whether they are true or not. For example, I upload b.jpg
and c.jpg
, where b.jpg
already exists. Both images get the success icon.
Now I upload d.jpg
and c.jpg
(note the order), where c.jpg
already exists and both images the the error
File already there
Does anybody have the same problem with the response? Maybe I'm doing the php-validation wrong? Or do I have to handle the dropzone-event-parameter (success, etc.) in another way? I tried successmultiple
, completemultiple
, etc. but with no success.
"Solved" it by switching from ProcessQueue to:
self.getQueuedFiles().forEach(function(element) {
self.processFile(element);
});
Brougth some other problems with it but they were solvable.