javascript - Receiving fake path while uploading - Stack Overflow

Whenever the uploading process happens through the Browsers rather than IE, the pathbelongs to the fi

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 badges
Add a ment  | 

5 Answers 5

Reset to default 1

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745671860a4639450.html

相关推荐

  • javascript - Receiving fake path while uploading - Stack Overflow

    Whenever the uploading process happens through the Browsers rather than IE, the pathbelongs to the fi

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信