Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery - get all fileNames inside input='file'

I have <input type="file" id="basicUploadFile" multiple="multiple"> and I want to get all file names inside this input. I've seen some example, but it gets only name of first file.

$ ('#basicUploadFile').live ('change', function () {     alert($ ('#basicUploadFile').val()); }); 

How can I do this? Thanks.

like image 575
Nolesh Avatar asked May 22 '12 13:05

Nolesh


1 Answers

var files = $('#basicUploadFile').prop("files") 

files will be a FileList object.

var names = $.map(files, function(val) { return val.name; }); 

Now names is an array of strings (file names)

FileAPI reference
files property reference

like image 84
wrock Avatar answered Sep 19 '22 18:09

wrock