Solved

HTML Select Directory

Posted on 2010-08-25
16
500 Views
Last Modified: 2012-05-10
I am looking to select just a directory in a HTML based form. I know most people will respond with a simple answer like <input name="userfile" type="file"> but I want to just select the path.

I know I could make them select a file and parse the whole path, but I just want them to select the folder that will be used. I'd like to not do things halfway if there is another way to do it.

So basically I'd like them to search and the returned result would be C:\folder instead of C:\folder\file.txt


Thanks!
0
Comment
Question by:CodeFlash
  • 7
  • 3
  • 3
  • +1
16 Comments
 
LVL 40

Expert Comment

by:RQuadling
ID: 33527117
The short answer is no.

<input type="file"> supplies only the filename, not the folder it is in.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33527133
You can only do that with JScript + ActiveX so only on IE : http://msdn.microsoft.com/en-us/library/2z9ffy99(VS.85).aspx

Javascript is not a language allowing access to computer ressources. Only microsoft and ActiveX open a breach here... if you allow ActiveX to do it of course...
0
 

Author Comment

by:CodeFlash
ID: 33527136
What if it is running locally? I know there's permission problems and all that if it's online.
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 100 total points
ID: 33527142
ActiveX is not available on other browser than Internet Explorer.
0
 

Author Comment

by:CodeFlash
ID: 33527145
I don't see how it's not possible. Using the <input type="file"> I can see the full file path in the box, how is there not a way to select just the path?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 33527170
What could you do with the path?  You can't upload a folder.  There is no support for that in any of the server languages that you could post to.
0
 

Author Comment

by:CodeFlash
ID: 33527191
I'm coding a local database program with PHP and MySQL. The folder select would be used to tell it where to get its data files (which it knows the names of) and to tell it where to put the backup SQL file. I just think a folder select would be much easier than making someone type out the path they want it to be put in.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 33527311
The <input name="userfile" type="file"> is going to try to upload something when you submit the form.  I don't see that that will do you any good.  You might be able to use 'scandir' http://us2.php.net/manual/en/function.scandir.php to create a list of directories that could be displayed.  Then you could use javascript to allow them to select the directory they want and put it in the form.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:CodeFlash
ID: 33527365
Is there anyway to make scandir as easy to use as the browse option on the form?
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 200 total points
ID: 33527410
You would have to write the code to do that.
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33529324
The <input type="file"> tag is for uploading ___FILES___. That's it. Nothing else. Not a folder. Not a hard drive.


To be able to get the additional information will require either a Java Applet (NOT JavaScript which is something entirely different) or an ActiveX control (limiting yourself to a single browser/OS/etc.)

http://lmgtfy.com/?q=java+uploader



To allow a server side script to display a list of files ... this means the server has access to the files ... at this point read http://www.codeguru.com/forum/showthread.php?t=301528 to see why a server cannot simply create a <input type="file"> tag with the filename pre-loaded.

If this is all for intranet, then make sure the server has read access to the client machines.

Use PHP's scandir() to read the client directory and to give a list of files with checkboxes.

The user can now check the files they want to be copied.

The server gets the list of checked files and copies them off the network, rather than as file uploads.

0
 

Author Comment

by:CodeFlash
ID: 33537862
@RQuadling

I dont want to upload anything, just log the directory they are placing their data files in. So my PHP script can load the text files they put into that directory at a later time.
0
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 200 total points
ID: 33540272
Then the reason why <input type="file"> fails is in the type...

directory/folder is NOT file

As this is an intranet, you are going to have to trawl the directory structure and present that yourself to the client to tag.

Or provide them with clear instructions on opening Explorer, navigating to the required location and then cutting/pasting the address from the address bar in Explorer to their browser.

Hmmm.

OOI, is there not a default place you should/could use? Something that all the user has to do is say "Yes" to? That way, for most users probably, you know where the location is and for those that want to change it, they can do the cut'n'paste dance?
0
 

Author Comment

by:CodeFlash
ID: 33542971
That's what I did last year, looks like it's what I'll be doing again. I just wanted to make it easier for anyone to use since some people aren't quite as smart about it and wanted to choose the drive.

Thanks for all your help guys!
0
 

Author Closing Comment

by:CodeFlash
ID: 33542985
Never got the response I hoped for, but it cleared it up
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33543907
Thanks for the points!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Javascript 2 decimals force two zeroes if needed 4 46
Bootstrap Datable Spinner 3 30
SVG Logo 4 18
CSS measurement 10 14
Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now