PDA

View Full Version : Javascript Directory Selection



cancer10
10-09-2008, 10:40 AM
Hi,

There is a scenario where I want my user to select the directory on their hard drive. Is there anyway I can prompt them with something like the following?


http://img136.imageshack.us/img136/4964/browseca9.jpg

http://thumbnails11.imagebam.com/1533/bd3b4a15320392.gif (http://www.imagebam.com/image/bd3b4a15320392)


PS: A cross browser script will be appreciated :)


Thanx

jscheuer1
10-09-2008, 02:42 PM
The image that you attempted to insert into your post is currently unavailable, so I have no idea what you mean. In javascript there is no longer any access to the file input element as far as its value goes. The user will be prompted to select a file from their hard drive. The directory will default to whatever it was the last time such a selection was made on that machine. You can ask them to select a particular directory, but you cannot force one on them. So no javascript required, or available - you can do:


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

as part of a form.

cancer10
10-09-2008, 02:59 PM
sorry about that, imageshack must be down now.

here is the screenshot again

http://thumbnails11.imagebam.com/1533/bd3b4a15320392.gif (http://www.imagebam.com/image/bd3b4a15320392)

jscheuer1
10-09-2008, 03:36 PM
Not with javascript. That sort of interface directly on a web page would have to be made with something like Active X controls (IE only, and often blocked*) or Java (cross browser if supporting plug in is installed, but also often blocked*). Flash might be able to do it, but I'm not aware of that as a possibility in Flash. There is also a slight possibility that something like that could be worked out using server side code like asp or PHP, but I highly doubt it.


*These methods are so often blocked, at least with a pop up asking the user if they want to install such and such a control, or one that says something like:


A web application wishes to access your hard drive.
It is strongly recommended that you refuse this unless you trust the author of this application.

Allow this application to access your hard drive? YES NO

because security feature on web browsers generally cannot distinguish between benign and malicious access of the local machine at this level.

Sometimes, depending upon the user's browser configuration, they might not be blocked at all, other times they may be blocked with no option given to the user to accept them, without the user even being aware of the attempt.

cancer10
10-10-2008, 07:01 AM
So is there any alternate to get a directory selection?

jscheuer1
10-10-2008, 08:50 AM
So is there any alternate to get a directory selection?

As I said, you can do:


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

as part of a form. It will not give you a directory selection, but it is an alternative to doing so. It will allow the user to select a file from his/her hard drive, and it will allow them to view the contents of their directories.

Why exactly do you want users to select a directory from their own computer? If you want - say, for them to upload the entire contents of a directory to your site, you could give them limited guest ftp like access via the server side if your host would allow that.

In fact, your host may even have such an interface available for you to provide to your users, ask your host.

However, such an interface (no matter how it is done) could potentially present problems, so as I say, just exactly what do you want this for?

cancer10
10-10-2008, 08:59 AM
well,

I want my user to add the directory where they would need the backups to be created.

The only problem with <input name="filename" type="file"> is that, the user needs to have atleast 1 or more file under the directory to make it work - not good.

also, since my site will run on a localserver hence I do not have any host.

If you want to ask why cannot I make my user type the path of the directory manually, the reason is:

1) I want the UI to be fancy.
2) To make my application more foolproof.

Thanx

jscheuer1
10-10-2008, 09:09 AM
What type of local host? The local host itself may provide that sort of functionality. In any case this is way outside what javascript alone can do. I'm confused though, are you setting up an intranet, or do you just want to provide a backup program over a LAN?

Perhaps you should post in Other:

http://www.dynamicdrive.com/forums/forumdisplay.php?f=12

or Java:

http://www.dynamicdrive.com/forums/forumdisplay.php?f=22

cancer10
10-10-2008, 09:11 AM
Ah well, an intranet site with a backup facility.

with localhost I meant LAN.


Thanx