Tags:


browsing to a directory, not a file
July 20, 2005 8:13 AM   RSS feed for this thread Subscribe

HTML's <input type="file"> allows you browse to a directory and select a file. Suppose I want to capture the directory path, not a file contained therein? Is it possible to browse to C:\Documents\Workstuff and capture *not* a file in that directory, but the directory path itself? Know what I mean?
posted by jpoulos to computers & internet (6 comments total)
The open file dialog requires the user to select a file, but you could use a regex to strip off the filename after selection.
posted by cbrody at 8:23 AM on July 20, 2005


But that way you couldn't select a directory that didn't contain any files.
posted by fvw at 8:24 AM on July 20, 2005


Perhaps this might help?
posted by Rothko at 8:42 AM on July 20, 2005


Curse the heavens!

Thanks, all.
posted by jpoulos at 9:19 AM on July 20, 2005


OK, if you have the user select any file in the directory you want, you can parse out the Content-Disposition header on the server side, and it should look something like:
'Content-Disposition: form-data; name="FileName2"; filename="C:\temp\test.txt"

Once you get the filename, it's trivial to parse out the directory.

You didn't mention what server side language, but here are the relevant RFCs.
RFC1867 - Form-based File Upload in HTML.
RFC1521 - MIME (Multipurpose Internet Mail Extensions) Part One:
posted by patrickje at 10:40 AM on July 20, 2005


patrickje: Web browsers report filename="test.txt", so that's not going to work. Doing otherwise would be a security leak.

jpoulos: You're not going to be able to do what you want to do using plain old HTML. File form elements only give you the contents of the file and the file name, nothing else.
posted by nmiell at 11:42 AM on July 20, 2005


« Older Help me put together my dream ...   |   I've written an album based on... Newer »
This thread is closed to new comments.