views:

3370

answers:

3

When I am using a form containing <input id="myFile" type="file" runat="server" /> to upload a file, my server-side code only sees the filename without the full path when using Firefox, while it works just fine in IE.

Is it possible to retrieve the full file path server-side in this case?

+3  A: 

You can never be sure of getting a full filepath or even a reliable filename or content-type submitted in a file upload file. Even if you get a full filepath you don't know what the path separator character is on the client's operating system, or whether a file extension (if present) denotes anything at all.

If your application requires the filepath/filename/content-type of a submitted file for anything more than giving the user a default title for the item uploaded, it's doing something wrong and will need fixing.

bobince
+4  A: 

You cannot. Actually, only IE gives this information which isn't important for the server in most cases. Neither FF nor Opera, at least, provide this info.
[UPDATE] Also tried with Safari, still no path... Somebody reported that Chrome might provide the info, although being a beta, that might change...

Perhaps you might need them in some intranet cases. In such case, you might ask the user to paste the path in a secondary input field... Not very friendly, but at least they will know they provide the info.

Actually, I know some people needed this info for some reasons, so they used JavaScript to pick up the path from the file input field and put it in an hidden field. FF developers found it was insecure (you can learn a lot from a simple path... like the login name of the user!) so prohibited such usage in FF3, making some people angry against this release...

References: Firefox 3's file upload box mentioned in Firefox 3 annoyance: Keying-in disabled in file upload control ...; also File input box disabled leads to great usability problem, among many other ones.

PhiLho
+2  A: 

I already stated this in a comment, but I think it bears repeating.

Microsoft opted to make the file control give the entire path to the file for use in intranet applications.

The HTML specification only makes mention of what the value should contain in one spot:

User agents may use the value of the value attribute as the initial file name.

However, they also have examples of what the multipart/form-data encoding should look like, and it doesn't contain the file path.

In other words, IE is breaking the standard and you can't rely on other browsers, even later versions of IE, to support it.

R. Bemrose