HTML Select Directory

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!
CodeFlashAsked:
Who is Participating?
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
You would have to write the code to do that.
0
 
Richard QuadlingSenior Software DeveloperCommented:
The short answer is no.

<input type="file"> supplies only the filename, not the folder it is in.
0
 
leakim971PluritechnicianCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
CodeFlashAuthor Commented:
What if it is running locally? I know there's permission problems and all that if it's online.
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
ActiveX is not available on other browser than Internet Explorer.
0
 
CodeFlashAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
CodeFlashAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
CodeFlashAuthor Commented:
Is there anyway to make scandir as easy to use as the browse option on the form?
0
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
CodeFlashAuthor Commented:
@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
 
Richard QuadlingConnect With a Mentor Senior Software DeveloperCommented:
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
 
CodeFlashAuthor Commented:
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
 
CodeFlashAuthor Commented:
Never got the response I hoped for, but it cleared it up
0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.