Select directory for HTML5 multiple file input in Firefox?

Wilhelm Kleu picture Wilhelm Kleu · Mar 1, 2012 · Viewed 19.9k times · Source

I want to allow users to select a local directory on a webpage (and then read all the files in the directory).

In Chrome I can add the webkitdirectory attribute to enable this functionality. According to a comment in this question and an answer to this question you should be able to do the same in firefox using mozdirectory but I am unable to get it to work.

I have tried the following in Firefox with no luck (works in Chrome):

 <input type="file" id="files" name="files[]" multiple mozdirectory="" webkitdirectory="" directory="" />

My Firefox version is 10.0.

Are there any way for a user to select a directory for input in Firefox without requiring an add-on on the client-side (like Flash)?

Answer

themihai picture themihai · Mar 19, 2012

Firefox doesn't have any API to upload directories yet (which is a shame)...not even in the nightly builds, so I don't think we will see support on this very soon. IE doesn't have one either. If you want to take advantage of this feature you must force the users to use Google Chrome (e.g. make them aware that upload directory is available only in Chrome).

A workaround would be to compress the directory in a .zip file and read it with the FileReader API. See https://stackoverflow.com/a/7842896/613453

Update
IE Edge now has support for this.
https://msdn.microsoft.com/en-us/library/mt574730(v=vs.85).aspx