html markup:
I am uploading multiples files with php. I want to make an array of upload files and send to server with ajax. how to make an array of the multiple selected files?
JavaScript:
jQuery.ajax({
url: 'insertfiles.php',
type: "POST",
data: {
file: // array of selected files.
},
success: function(data){
},
error: function(data){
alert( 'Sorry.' );
}
});
Answer
Modern browsers that support the HTML5 file stuff have in the element a "files" property.
That will give you a file list reference, which has a length
property.
As the property is already an array
so you just need to access it or iterate through it.
JS
var input = document.getElementById('id');
console.log(input.files);
for (var i = 0; i < input.files.length; i++) {
console.log(input.files[i]);
}
No comments:
Post a Comment