Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow the user to pick any file or directory in an <input type="file"> tag?

By creating an input tag such as:

<input type="file">

The user isn't able to select directories. By enabling certain flags:

<input type="file" webkitdirectory mozdirectory msdirectory odirectory directory multiple>

The user can now pick any directory, but not single files.

Is there any way to enable both?

like image 747
MaiaVictor Avatar asked Mar 06 '17 18:03

MaiaVictor


2 Answers

You can only enable one of the two.

<input type="file" id="myFiles" webkitdirectory mozdirectory msdirectory odirectory directory multiple>

The only way to select both files and directories using 'standard' ways is by providing two separate input elements.

Anyway, when you select a directory the files are available through the DOM object using document.getElementById('myFiles').

like image 50
Rahul Arora Avatar answered Sep 20 '22 18:09

Rahul Arora


For now this is not possible.

There are several requests open for mozilla and chrome, you might want to keep up with them.

like image 39
Koby Douek Avatar answered Sep 21 '22 18:09

Koby Douek