Retrieving the full path (server-side) of a file uploaded using Firefox?

后端 未结 3 1875
无人及你
无人及你 2020-12-11 20:59

When I am using a form containing to upload a file, my server-side code only sees the filename with

相关标签:
3条回答
  • 2020-12-11 21:41

    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.

    0 讨论(0)
  • 2020-12-11 21:54

    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.

    0 讨论(0)
  • 2020-12-11 21:58

    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.

    0 讨论(0)
提交回复
热议问题