如何解决C:\fakepath? [英] How to resolve the C:\fakepath?

查看:1091
本文介绍了如何解决C:\fakepath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<input type="file" id="file-id" name="file_name" onchange="theimage();">

这是我的上传按钮。

<input type="text" name="file_path" id="file-path">

这是我必须显示文件完整路径的文本字段。

This is the text field where I have to show the full path of the file.

function theimage(){
 var filename = document.getElementById('file-id').value;
 document.getElementById('file-path').value = filename;
 alert(filename);
}

这是解决我的问题的JavaScript。但是在警报值中给我

This is the JavaScript which solve my problem. But in the alert value gives me

C:\fakepath\test.csv 

,Mozilla给了我:

and Mozilla gives me:

test.csv

但是我想要本地的完全限定文件路径。如何解决这个问题?

But I want the local fully qualified file path. How to resolve this issue?

如果这是由于浏览器的安全性问题,那么应该采用哪种替代方式呢?

If this is due to browser security issue then what should be the alternate way to do this?

推荐答案

某些浏览器具有防止JavaScript知道文件本地完整路径的安全功能。这是有道理的 - 作为客户端,您不希望服务器知道您的本地机器的文件系统。如果所有浏览器都这样做,这将是很好的。

Some browsers have a security feature that prevents JavaScript from knowing your file's local full path. It makes sense - as a client, you don't want the server to know your local machine's filesystem. It would be nice if all browsers did this.

这篇关于如何解决C:\fakepath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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