8

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.

2
  • Both is not possible up to date. Commented Nov 24, 2016 at 12:46
  • off-topic: remove spaces between attributes, values and =... so id="file" instead of id = "file" Commented Nov 24, 2016 at 14:59

1 Answer 1

2

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 :/

Sign up to request clarification or add additional context in comments.

2 Comments

What is the benefit of folder upload if we can't get folders on server side?
The drag&drop thing should work (you can test it here). But what is not possible though is to have the dialog for both directories and single/multiple files. I am not entirely sure, but I think it's even an OS restriction (at least on osX).

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.