how to get value of html 5 multiple file upload variable using jquery?

╄→гoц情女王★ 提交于 2019-12-12 08:13:33

问题


even though i select multiple files using below html.

<input type="file" id="multiplefiles" name="uploadedfile[]" multiple>

I only get value of first file selected. i am using a simple:

var filelist = $("#multiplefiles").val() || [];
$.each(filelist, function(i, myfile) {
  console.log('found file '+i+' ='+myfile);
});

please advise how do i get list of all files...

for example selected string in the input field is: C:\Users\Public\Pictures\Sample Pictures\Hydrangeas.jpg, C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg, C:\Users\Public\Pictures\Sample Pictures\upload-2.txt

and from above logic i only get: following in log:

found file 0 =Hydrangeas.jpg

ty. Rajeev


回答1:


This should do the trick:

var filelist = document.getElementById("multiplefiles").files || [];
for (var i = 0; i < filelist.length; i++) {
    console.log('found file ' + i + ' = ' + filelist[i].name);
}

A working jsFiddle is here.



来源:https://stackoverflow.com/questions/14035530/how-to-get-value-of-html-5-multiple-file-upload-variable-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!