Answer the question
In order to leave comments, you need to log in
Why does $_FILES contain only the last file sent by the array?
Hello, there is a form in which you can select multiple files (multiple="true"). I write all the files to the FormData object and send it to the server, but there, in $_FILES, there is only the last file for some reason.
html:
<input type="file" name="file" id="file-input" multiple="true">
var fd = new FormData();
for (var i = 0; i < input.files.length; i++) {
fd.append('file', input.files[i]);
}
$.ajax({
url: 'server.php',
data: fd,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
console.log(data);
}
});
var_dump($_FILES);
array(1) {
["file"]=>
array(5) {
["name"]=>
string(14) "myypdf (5).pdf"
["type"]=>
string(15) "application/pdf"
["tmp_name"]=>
string(56) "some\php_upload\php6133.tmp"
["error"]=>
int(0)
["size"]=>
int(428652)
}
}
Answer the question
In order to leave comments, you need to log in
for (var i = 0; i < input.files.length; i++) {
fd.append('file['+i+']', input.files[i]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question