Billy
Billy

Reputation: 905

How to get multiple files in Fileupload

<input type="file" id="fup" multiple/>
alert($("#fup").val());

Here I am getting only single file in the alert() even though I am selecting multiple files. How can I get multiple files in the alert() with complete url path?

Upvotes: 0

Views: 40

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337560

Use the files collection of the underlying DOMElement:

var files = $('#fup')[0].files;
for (var i = 0; i < files.length; i++) {
    console.log(files[i].name);
}

Working example

Also note that you shouldn't use alert() for debugging. It coerces the datatypes and is generally not a good idea. The console is always preferable.

Upvotes: 1

Related Questions