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

查看:31
本文介绍了使用 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:

当使用 input 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.

这个问题.指的是在服务端获取值,但是在表单提交前的JavaScript中也是一样的问题.

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天全站免登陆