2

For example, there is a field:

<input type="file" name="files[]" multiple="multiple" class="multiupload" />

How can I acces all the files list when multiple files have selected?

$('.multiupload').val() returns only first file name. I trying to do this in Google Chrome.

4
  • Vanilla JavaScript has to be used: $('.multiupload')[0].files[i].name (where i = index of file, 0, 1, 2, ...). Commented Jun 18, 2012 at 9:03
  • 2
    possible duplicate of Retrieving file names out of a multi-file upload control with javascript Commented Jun 18, 2012 at 9:04
  • Can you post your code on http://jsfiddle.net/? Commented Jun 18, 2012 at 9:14
  • I'm sorry, my question is really duplicates that. That question has the workable example. Commented Jun 18, 2012 at 9:38

1 Answer 1

8
$('.multiupload').map(function(){
  return $(this).val();
});

Update: For using multiple attribute for one input filed, there is files property you could get.

$.map($('.multiupload').get(0).files, function(file) {
  return file.name;
});
Sign up to request clarification or add additional context in comments.

7 Comments

Are you sure that this works? He has one input[type=file] with the multiple attribute. Your code iterates over multiple elements.
@ThiefMaster Doesn't he want multiple values?
@xdazz: Yes, but in a single input field, not with multiple fields. I.e. similar to what <select multiple> does.
I tried with ur code, but its not working, selected 3 files, but getting alert for first file, jsfiddle.net/ranganadh/EXann
@xdazz Rob W's link gives the answer, check this jsfiddle.net/ranganadh/EXann/1
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.