I am trying to implement a multiple image uploader in jQuery using the new HTML5 multiple attribute.
My code is the following:
<form action="file-upload.php" method="post" enctype="multipart/form-data">
<input name="userfiles" type="file" multiple="multiple">
</form>
The JS code I am using is taken from a discussion here on SO, and is the following:
$('input[name=userfiles]').change(function() {
var names = [];
for (var i = 0; i < $(this).get(0).files.length; ++i) {
names.push($(this).get(0).files[i].name);
console.log(names[i]);
}
});
With this I am able to print on the console the file names I select, but what if I need to get the exact val() of those files? I tried replacing .name with .val(), but I get an error.
I think I would need a fakepath of every single file if I want to be able to work with them with $.ajax. If this is correct, how can I cycle though them in the PHP file where the get request is sent, in order to upload them?