javascript - How to resolve the C:fakepath

javascript – How to resolve the C:fakepath?

javascript – How to resolve the C:fakepath?

Some browsers have a security feature that prevents JavaScript from knowing your files local full path. It makes sense – as a client, you dont want the server to know your local machines filesystem. It would be nice if all browsers did this.

Use

document.getElementById(file-id).files[0].name; 

instead of

document.getElementById(file-id).value

javascript – How to resolve the C:fakepath?

I use the object FileReader on the input onchange event for your input file type! This example uses the readAsDataURL function and for that reason you should have an tag. The FileReader object also has readAsBinaryString to get the binary data, which can later be used to create the same file on your server

Example:

var input = document.getElementById(inputFile);
var fReader = new FileReader();
fReader.readAsDataURL(input.files[0]);
fReader.onloadend = function(event){
    var img = document.getElementById(yourImgTag);
    img.src = event.target.result;
}

Related posts on java script  :

Leave a Reply

Your email address will not be published.