Currently I am using jQuery to read the value of a file input to read the file extension and determine if it is a zip file. (It does not matter that I get fakepath as I only need access to the filename.) When I have multiple set on the input tag and I select multiple files .val() only grabs the path of the last file that was selected. Is there any way to iterate through each one?
Share
The HTML5 File API defines a
FileListobject which is accessible through thefilesproperty of the event target. You could do something like this:The
FileListobject contains a list ofFileobjects, and thenameproperty should give you the name you’re looking for:Here’s a working example.
Edit
Previously, I showed the use of the
originalEventproperty of the jQuery event object. This was unnecessary since thetargetproperty is present on the jQuery event object as well as the original event object.