Results 1 to 9 of 9

Thread: Javascript Directory Selection

  1. #1
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Question Javascript Directory Selection

    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?







    PS: A cross browser script will be appreciated


    Thanx
    Last edited by cancer10; 10-09-2008 at 02:58 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    HTML Code:
    <input name="filename" type="file">
    as part of a form.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default

    sorry about that, imageshack must be down now.

    here is the screenshot again


  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default

    So is there any alternate to get a directory selection?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by cancer10 View Post
    So is there any alternate to get a directory selection?
    As I said, you can do:

    HTML Code:
    <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?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default

    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

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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/f...splay.php?f=12

    or Java:

    http://www.dynamicdrive.com/forums/f...splay.php?f=22
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default

    Ah well, an intranet site with a backup facility.

    with localhost I meant LAN.


    Thanx

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •