使用jQuery输入文件的完整路径 [英] Full path from file input using jQuery

查看:108
本文介绍了使用jQuery输入文件的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I call val() on an input with type="file" I only get file name rather than full path. How can I get full path?

推荐答案

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

You can't: It's a security feature in all modern browsers.

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

For IE8, it's off by default, but can be reactivated using a security setting:

使用输入的type = file对象选择文件时,value属性的值取决于用于显示的安全区域的将文件上传到服务器时包括本地目录路径"的安全设置的值.包含输入对象的网页.

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.

仅当启用此设置时,才返回所选文件的标准文件名.禁用此设置后,Internet Explorer 8将使用字符串C:\ fakepath \替换本地驱动器和目录路径,以防止不当的信息泄露.

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.

在我所知道的所有其他当前主流浏览器中,该功能也已关闭.文件名是最好的.

In all other current mainstream browsers I know of, it is also turned off. The file name is the best you can get.

More detailed info and good links in this question. It refers to getting the value server-side, but the issue is the same in JavaScript before the form's submission.

这篇关于使用jQuery输入文件的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆