The Mystery of c:\fakepath Unveiled

Try Semtex – the new HTML5, CSS3 and JavaScript UI framework!

Have you tried to manipulate the string that is returned by the value attribute of a file upload input (<input type="file" />) under Internet Explorer 8? Did you get the strange c:\fakepath string? Relax – there is nothing wrong with your code, and although this is quite confusing, it has its justifiable reasons. Here is a screenshot of a file input control manipulated with JavaScript:


According to the specifications of HTML5, a file upload control should not reveal the real local path to the file you have selected, if you manipulate its value string with JavaScript. Instead, the string that is returned by the script, which handles the file information is c:\fakepath.

This requirement is already implemented in Internet Explorer 8 – the real path to the file will be shown only if the page that contains the control is added to the trusted sites collection of the browser.

Below is some code to play with. Notice that this will not work on localhost pages. The page should be uploaded on a production server.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="" dir="ltr" lang="en">
<title>Testing the FakePath String</title>
<form id="Form1" action="" method="post">
<input type="file" /><input type="button" onclick="alert(this.previousSibling.value);" value="select file and press the button" />

More Cool Stuff



  1. Q: why the hell did a ‘C:\fakepath’ made it into a STANDARD???
    Why not simply leave it empty, no path, just the plain file name? This looks totally weird on any none-windows system.
    Or is anybody at microsoft concerned about at least leaving some traces for the time after windows has become obsolete???

  2. ah, jesus, i was searching my whole project code, like, this MUST be from early debugging or something. bah– and it worked in Firefox the whole time so I had no suspicions.

  3. get the first file from control and then get the name of the file, it will ignore the file path on chrome, and also will make correction of path for ie broswers. on saving the file, you have to use, method to get the file name only for ie browsers
    var fileUpload = $(“#ContentPlaceHolder1_FileUpload_mediaFile”).get(0);
    var files = fileUpload.files; var mediafilename = “”;
    for (var i = 0; i < files.length; i++) { mediafilename = files[i].name; }

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s