View Full Version : Where does "Browse" start for input type="file"

02-24-2011, 08:04 PM
I allow authorized users to upload files for the public to download. My php handler works as intended. It is called from the server with a simple HTML script using an input box with type="file". It is a complete mystery as to where the Browse button starts looking. Users ask me and I have no idea.

Apparently, once a user selects a file, the next time he or she uses the script Browse starts at that last directory. This is different for each user, of course.

Although the script and handler work, I feel rather strange not knowing how it works. Anyone know where the Browse button for the HTML input box starts or, better yet, how to control it?

02-24-2011, 09:19 PM
The browse button is added by the browser, when the browser sees an input type of file it automatically adds the browse button for you and the browser tells that button to search a local directory when clicked. As far as manipulating the browse button, this can be done, but it's tricky if you don't know what your doing. Maybe this link can help you understand how to execute this.

Link: http://www.quirksmode.org/dom/inputfile.html

02-24-2011, 11:36 PM
I wondered which local directory the Browse button started with.
Apparently is uses the last directory your browser accessed for a file. For example, in Firefox if one clicks File:Open File and actually opens a file, the Browser button starts with that directory.

about:config browser.open.lastDir contains that information for Firefox.

I don't know how to grab that information with Javascript or php.

However, for our purposes I will just tell users to access (with their browser) the file they want to upload before using my script to actually upload to the server.

Thanks for the comment.