admin管理员组文章数量:1435859
Whenever the uploading process happens through the Browsers rather than IE, the path
belongs to the file from client side systems is showing like "c:/fakepath/x.jpg"..! I tried out lot of
Solutions from the web to rectify that, but nothing works..! If anybody successfully tackled this
problem before Just send me your solution..!
HTML code that i used
<form name="xx" enctype="multipart/form-data">
<input type="file" name="up"/>
</form>
My Java script..
alert(document.xx.up.value);
But it is displaying "c:/fakepath/x.jpg" in all browsers except IE.
Whenever the uploading process happens through the Browsers rather than IE, the path
belongs to the file from client side systems is showing like "c:/fakepath/x.jpg"..! I tried out lot of
Solutions from the web to rectify that, but nothing works..! If anybody successfully tackled this
problem before Just send me your solution..!
HTML code that i used
<form name="xx" enctype="multipart/form-data">
<input type="file" name="up"/>
</form>
My Java script..
alert(document.xx.up.value);
But it is displaying "c:/fakepath/x.jpg" in all browsers except IE.
Share Improve this question edited Feb 28, 2012 at 5:18 Michael Fredrickson 37.4k6 gold badges95 silver badges110 bronze badges asked Feb 28, 2012 at 4:36 Rajaprabhu AravindasamyRajaprabhu Aravindasamy 67.2k17 gold badges106 silver badges132 bronze badges5 Answers
Reset to default 1This is a browser security restriction. You can't set the value of the file upload control via script, nor can you read the correct path.
Modern browsers won't tell you what the actual path of the file is, because it's really none of your business as an application programmer, and is likely to contain private user information (e.g, their username).
There is no workaround. Learn to live without that information.
This post shows a way to remove the 'fakepath' display:
// Change the node's value by removing the fake path
inputNode.value = fileInput.value.replace("C:\fakepath\", "");
Change the ClientId of the AsyncFileUpload control from Inherit to AutoId
Adding some few more steps to your code and introducing a change event, you could retrieve the file object from the event target if there is a file selected at all.
<form name="xx" enctype="multipart/form-data">
<input type="file" onchange="fileChangeAction(event)" name="up"/>
</form>
<script>
const fileChangeAction = ($event) => {
let file;
if($event.target) {
if($event.target.files) {
file = $event.target.files[0];
}
}
console.log(file);
}
</script>
本文标签: javascriptReceiving fake path while uploadingStack Overflow
版权声明:本文标题:javascript - Receiving fake path while uploading - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745671859a2669615.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论