Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I upload folder and files both from same input type?

Tags:

html

I am using a form where I can upload both, a file or full folder. I am using following code:

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

With first input, I can upload file but not folder and with 2nd input, I can upload folder but not file. But I want to be able to upload both with same input.

Please tell me what is the exact code by which I can upload both file and folder in single click.

like image 969
R. Dey Avatar asked Nov 24 '16 12:11

R. Dey


People also ask

How can I upload a folder to multiple files?

Right click an empty space on your desktop or documents area; choose New > Compressed (zipped) folder. Give your zipped folder a name. To move multiple files in to this folder simply drag and drop or copy and paste your desired files into your new zipped folder.

How do you upload a folder to one file?

Select New > Folder to create a folder. From the folder you want to upload, select the files. Drag and drop the files into the new folder you created in OneDrive.


1 Answers

As I'm writing this, this is not possible with pure HTML, unless you use some plugin like Flash then maybe it's possible.

1 file upload:

<input type="file" name="file">

Multiple files upload (but must be in same folder):

<input type="file" name="file[]" multiple>

1 folder upload (Note: not all browsers may support this):

<input type="file" name="file" webkitdirectory directory>

Multiple folders upload maybe not possible currently.

Here is a trick that might work (but I didn't test it): You can drag and drop file(s) and folder(s) directly in the input field, for example from your desktop to the browser's input. Try selecting files AND folders and drog-n-drop them in your input field, but I don't know if they will be uploaded correctly to the server.

EDIT:

Just tested that trick, it didn't work :/

like image 63
evilReiko Avatar answered Nov 15 '22 05:11

evilReiko