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

查看:48
本文介绍了如何解决 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	est.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天全站免登陆