Im using single file input field with multiple upload property. I've already tested single file pass like that and it worked. Now I'm trying to pass files using an array but there is a mistake. There is no form.
HTML:
<input id="fileInfo" name="userfile[]" type="file" multiple>
JS:
var formData = new FormData();
var files = [];
for(var i = 0; i < length; i++) {
files[i] = $('input', '#fileInfo')[0].files[i];
}
formData.append('userfile', files);
$.ajax({
url: "example.php",
data: formData,
type: 'POST',
dataType: 'json',
processData: false,
contentType: false,
success: function(res)
{
console.log("done");
}
});
PHP:
<?php
$length = sizeof($_FILES['userfile']['name']);
json_encode(array($length));
error.log:
PHP Notice: Undefined index: userfile in /path/to/php on line 2, referer: http://localhost/test