This question already has an answer here:
C:\fakepath\ is simply something that is added in by the browser for security purposes andshouldn't be present when the actual values are posted to the server.
If you wanted to replaced them for display in your
alert() call (or for other purposes), you could just try replacing it via a
// This should strip off 'C:\fakepath\' from your file path var ab = document.getElementById("myfile").value.replace('C:\\fakepath\\',''); alert(ab);
You can see a complete working example below (just add a file) :
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Fakepath Eraser Pro</title> </head> <body> <input type='file' onchange='alert(this.value.replace("C:\\fakepath\\",""))' /> </body> </html>
You could try replace?
var ab = document.getElementById("myfile").value.replace(/C:\\fakepath\\/i, '');
"\" is a special character and it has to be escaped in strings to work properly.
var path = "C:\\fakepath\\abc.pdf"; var array = path.split("\\"); console.log(array[array.length-1]); // output will be "abc.pdf"