如何从文件输入中获取文件的完整路径 [英] How to get the full path of the file from a file input
问题描述
可能存在重复:
使用jQuery文件输入的完整路径 >我有以下html元素< input type =fileid =upload>
如果我使用
$( #上传)VAL();
我只是文件名,而不是文件的完整绝对路径。有人能告诉我如何获得完整的路径吗?
解决方案您无法这样做 - 浏览器不会允许这个,因为安全问题。虽然有解决方法,事实是,你不应该指望这个工作。以下堆栈溢出问题与此处相关:
- http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018981.html
- c:\的神秘之处fakepath Unveiled
因此,尝试获取路径在新浏览器中会变得毫无用处 - 您实际上会得到一个虚假一个代替。
Possible Duplicate:
Full path from file input using jQueryI have the following html element
<input type="file" id="upload">
If I use
$("#upload").val();
I only the file name, not the complete absolute path of the file. Can someone tell me how do get the complete path?
解决方案You cannot do so - the browser will not allow this because of security concerns. Although there are workarounds, the fact is that you shouldn't count on this working. The following Stack Overflow questions are relevant here:
In addition to these, the new HTML5 specification states that browsers will need to feed a Windows compatible fakepath into the
input type="file"
field, ostensibly for backward compatibility reasons.
- http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018981.html
- The Mystery of c:\fakepath Unveiled
So trying to obtain the path is worse then useless in newer browsers - you'll actually get a fake one instead.
这篇关于如何从文件输入中获取文件的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!