Solved

HTML Select Directory

Posted on 2010-08-25
16
509 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:Richard Quadling
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 83

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 83

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
 

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 83

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:Richard Quadling
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:Richard Quadling
Richard Quadling 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

775 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