tags:

views:

160

answers:

2

How can I create a directory chooser in html page.
If I use input file element I can select file only, but I need to select directory instead.
I need to do this beacause the user should select a right path inside his computer.
Any solutions ?

+2  A: 

Can't be done in pure HTML/JavaScript for security reasons.

Selecting a file for upload is the best you can do, and even then you won't get its full original path in modern browsers.

You may be able to put something together using Java or Flash (e.g. using SWFUpload as a basis), but it's a lot of work and brings additional compatibility issues.

Another thought would be opening an iframe showing the user's C: drive (or whatever) but even if that's possible nowadays (could be blocked for security reasons, haven't tried in a long time) it will be impossible for your web site to communicate with the iframe (again for security reasons).

What do you need this for?

Pekka
I need it for select a path inside computer, not for upload.I use this path to save file, but with JSP function.
enfix
@enfix how are you going to save a file from a JSP server into a certain path on the user's local computer? I don't understand. Can you edit your question to clarify?
Pekka
I need to get the path where the user want save files, but the files are saved with java function callend inside JSP page.This function need a path where to save files. That's all.I save more than one file, i need to create folders and other things with this java function.
enfix
@enfix but why do you need the path from the *user's* computer for this when you are going to save files on the *server* ?
Pekka
No, I need to save in user's computer by java function.Sorry for my bad english...
enfix
@enfix no problem, but how are you going to do this? Are you using a Java applet in the user's browser already?
Pekka
No, not a java applet, I use a JSP page. Inside this I use an object with a method SaveResult(Selected_files, Path). Path is the parameter that I need to get from the HTML or JSP page.
enfix
@enfix you can't save a file on the client's computer from the server. It's totally impossible. You would have to serve the file as a regular file download, and the browser will then offer the user to choose the directory to save the file in. That is completely out of your control, though. You can't influence that part of the process.
Pekka
A: 

Scripting is inevitable.

This isn't provided because of the security risk. <input type='file' /> is closest, but not what you are looking for.

Checkout this example that uses Javascript to achieve what you want.

If the OS is windows, you can use VB scripts to access the core control files to browse for a folder.

KMan