如何从输入类型文件获取完整的文件路径? [英] how to get full file path from input type file?

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

问题描述



如何从输入类型文件中获取完整的文件路径?

Hi,
how to get full file path from input type file?

推荐答案

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



对于IE8,它默认是关闭的,但可以使用安全设置重新激活:



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

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

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.





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



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


你好,



这是一个展示这一点的小样本。希望这就是你所期待的。

Hello,

Here is a small sample demonstrating this. Hope this is what you are looking.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function showFileName() {
   var fil = document.getElementById("myFile");
   alert(fil.value);
}
</script>
</head>
<body>
<form id="frmMain" name="frmMain">
    <input type="file" id="myFile" name="myFile"/>
    <a href="#" onclick="showFileName()">Show Name</a>
</form>
</body>
</html>



注意 出于安全考虑,大多数浏览器只返回文件名,而不是完整路径和文件名。 IE6及以下浏览器将返回所需的值



问候,


NoteFor security reasons most of the browser's will only return the file name and not the full path and file name. IE6 and below browsers will return you the desired value

Regards,


这篇关于如何从输入类型文件获取完整的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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