jQuery 如何从文件输入中获取文件的完整路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4176377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:47:23  来源:igfitidea点击:

How to get the full path of the file from a file input

jqueryhtml

提问by Vidya

Possible Duplicate:
Full path from file input using jQuery

可能的重复:
使用 jQuery 的文件输入的完整路径

I have the following html element

我有以下 html 元素

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

我只有文件名,没有文件的完整绝对路径。有人可以告诉我如何获得完整路径吗?

回答by Yi Jiang

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.

除此之外,新的 HTML5 规范指出input type="file",表面上是出于向后兼容性的原因,浏览器需要向该领域提供与 Windows 兼容的假路径。

So trying to obtain the path is worse then useless in newer browsers - you'll actually get a fake one instead.

因此,在较新的浏览器中,尝试获取路径更糟,而且毫无用处——您实际上会得到一个假的。