0

I am using webkit directory to upload folders into the server. Its working fine. I wanted to know if it possible to give path of folder to webkit directory to be uploaded to server without using dialog? Like I know which folder to be uploaded on server, I will give its path to webkit directory and it will upload full folder for me?

For example, after the user selects foo.html, can the folder foo be uploaded automatically?

 /foo.html
 /foo/...
whitehat101
  • 2,428
  • 23
  • 18
Muneem Habib
  • 1,046
  • 4
  • 18
  • 49

2 Answers2

0

No.

That is not allowed for security reasons. You cannot grab arbitrary files from the file system without user interaction. Otherwise, what would stop websites from stealing anything they wanted from a user's computer?

The user must select a file/folder for it to be uploaded.

If you want that kind of functionality, you would need a native app.

Once the user has selected a file, you cannot access the path of the file either. All modern browsers provide false paths when you ask for the value of the file picker input. See this question about unsuccessfully attempting to get that information.

Community
  • 1
  • 1
whitehat101
  • 2,428
  • 23
  • 18
  • sir actually what i wanted is user selects the file and there will be a folder with the same filename both the file and folder will be uploaded to server. i have done folder uploading to the server the only thing which is driving me crazy is how to give folder path when user selects the file. – Muneem Habib Sep 30 '13 at 11:36
  • Ah, so after the user selects a file, you want the name of the folder? I don't think this is possible, again for security reasons. I think it's safari, that will claim the file is `C:/fakepath/filename.txt` – whitehat101 Sep 30 '13 at 11:48
  • You might be able to instruct the user to select both, the file and the folder, if webkit directory accepts multiple inputs. – whitehat101 Sep 30 '13 at 11:49
  • sir can u answer my question. Suppose that i have a file in my local system i want this file to be uploaded to server. I will choose its path from a dialog. But i want to give its path by myself without opening a dialog?\ – Muneem Habib Sep 30 '13 at 11:51
  • You cannot programatically set the path of a file/folder to be uploaded. It must be through a dialog with user interaction for security reasons. – whitehat101 Sep 30 '13 at 11:53
  • supposedly, I have a dilaog i have chosen a file now its path is save some where i wanted to know where that path is save? – Muneem Habib Sep 30 '13 at 12:33
  • You cannot relyably access the file's path on the user's computer. See: http://stackoverflow.com/questions/4851595/how-to-resolve-the-c-fakepath – whitehat101 Sep 30 '13 at 13:34
-1

You cannot upload a folder as a whole , but you could upload multiple files at the same time.

This is a code excerpt from w3schools.

<form action="demo_form.asp">
  Select images: <input type="file" name="img" multiple>
  <input type="submit">
</form> 

Adding the keyword multiple to the file input tag enables you to select multiple files to upload.

Mevin Babu
  • 2,405
  • 21
  • 34