jquery - 使用 jQuery 输入文件的完整路径

标签 jquery input file-type

当我在带有 type="file" 的输入上调用 val() 时,我只获得文件名而不是完整路径。如何获得完整路径?

最佳答案

你不能:这是所有现代浏览器中的一项安全功能。

对于IE8 ,默认情况下它处于关闭状态,但可以使用安全设置重新激活:

When a file is selected by using the input type=file object, the value of the value property depends on the value of the "Include local directory path when uploading files to a server" security setting for the security zone used to display the Web page containing the input object.

The fully qualified filename of the selected file is returned only when this setting is enabled. When the setting is disabled, Internet Explorer 8 replaces the local drive and directory path with the string C:\fakepath\ in order to prevent inappropriate information disclosure.

在我所知道的所有其他当前主流浏览器中,它也被关闭。文件名是您能得到的最好的文件名。

更详细的信息和良好的链接在 this question 。它指的是在服务器端获取值,但在表单提交之前的 JavaScript 中,问题是相同的。

关于jquery - 使用 jQuery 输入文件的完整路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3489133/

相关文章:

php表单mysql错误到数据库

java - 检测给定文件是否为图像并且是否为 java 中特定类型的有效图像

javascript - JS 和 CSS 中的内容 slider

javascript - 克隆行时清除隐藏输入

css - 更改高度后如何换行和对齐?

java - 在java中打印文件类型

c# - 有没有办法以编程方式设置 "UserChoice"注册表项以接管文件类型关联?

javascript - 在无限循环风格的展示中预加载相邻条目

php - 无法从 Plupload 获取 JSON 数据

jquery - 我们可以将 jQuery 引用添加到 web.config 文件中,而不是将其添加到每个 asp.net 页面吗?