2

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.

Michael Fredrickson
  • 36,839
  • 5
  • 92
  • 109
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130

5 Answers5

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.

Sam
  • 4,219
  • 7
  • 52
  • 80
  • Yeah its right.! I came to know about this while i'm surfing to find a remedy. Then how can we upload a file to our server..? is there any peculiar way to achieve that..? give me a clue. – Rajaprabhu Aravindasamy Feb 28 '12 at 04:44
  • The fact that it shows c:\fakepath\{file} doesn't mean that the file won't upload - it will. You just can't see the path. – Sam Feb 28 '12 at 04:46
1

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.

0

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\", "");

Community
  • 1
  • 1
Eyal Levin
  • 16,271
  • 6
  • 66
  • 56
0

Change the ClientId of the AsyncFileUpload control from Inherit to AutoId

0

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>