检索使用Firefox上传的文件的完整路径(服务器端)?

时间:2021-11-29 04:19:27

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.

当我使用包含的表单上传文件时,我的服务器端代码在使用Firefox时只看到没有完整路径的文件名,而它在IE中运行得很好。

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

在这种情况下,是否可以检索服务器端的完整文件路径?

3 个解决方案

#1


8  

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...

你不能。实际上,在大多数情况下,只有IE提供这些对服务器不重要的信息。 FF和Opera至少都没有提供这些信息。 [更新]也试过Safari,仍然没有路径......有人报道Chrome可能会提供信息,虽然是测试版,可能会改变...

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.

也许您可能在某些Intranet案例中需要它们。在这种情况下,您可能会要求用户将路径粘贴到辅助输入字段中...不是很友好,但至少他们知道他们提供了信息。

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...

实际上,我知道有些人出于某些原因需要这些信息,因此他们使用JavaScript从文件输入字段中选取路径并将其放在隐藏字段中。 FF开发人员发现它不安全(你可以从一个简单的路径中学到很多东西......比如用户的登录名!)所以禁止在FF3中使用这种用法,让一些人对这个版本感到愤怒......

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.

参考文献:Firefox 3中提到的F​​irefox 3的文件上传框烦恼:文件上传控制中禁用键控...;禁用文件输入框会导致很大的可用性问题,以及许多其他问题。

#2


3  

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.

如果您的应用程序需要提交文件的文件路径/文件名/内容类型,而不仅仅是为用户提供上传项目的默认标题,那么它会出错并且需要修复。

#3


2  

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.

Microsoft选择让文件控件提供文件的完整路径,以便在Intranet应用程序中使用。

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

HTML规范仅在一个位置提及值应包含的内容:

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

用户代理可以使用value属性的值作为初始文件名。

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.

换句话说,IE正在打破标准,你不能依赖其他浏览器,甚至更高版本的IE来支持它。

#1


8  

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...

你不能。实际上,在大多数情况下,只有IE提供这些对服务器不重要的信息。 FF和Opera至少都没有提供这些信息。 [更新]也试过Safari,仍然没有路径......有人报道Chrome可能会提供信息,虽然是测试版,可能会改变...

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.

也许您可能在某些Intranet案例中需要它们。在这种情况下,您可能会要求用户将路径粘贴到辅助输入字段中...不是很友好,但至少他们知道他们提供了信息。

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...

实际上,我知道有些人出于某些原因需要这些信息,因此他们使用JavaScript从文件输入字段中选取路径并将其放在隐藏字段中。 FF开发人员发现它不安全(你可以从一个简单的路径中学到很多东西......比如用户的登录名!)所以禁止在FF3中使用这种用法,让一些人对这个版本感到愤怒......

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.

参考文献:Firefox 3中提到的F​​irefox 3的文件上传框烦恼:文件上传控制中禁用键控...;禁用文件输入框会导致很大的可用性问题,以及许多其他问题。

#2


3  

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.

如果您的应用程序需要提交文件的文件路径/文件名/内容类型,而不仅仅是为用户提供上传项目的默认标题,那么它会出错并且需要修复。

#3


2  

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.

Microsoft选择让文件控件提供文件的完整路径,以便在Intranet应用程序中使用。

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

HTML规范仅在一个位置提及值应包含的内容:

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

用户代理可以使用value属性的值作为初始文件名。

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.

换句话说,IE正在打破标准,你不能依赖其他浏览器,甚至更高版本的IE来支持它。