What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

Possible Duplicate:
The image uploader shows “fakepath” as path when using Chrome

On Mac OS X, when you upload an image, you get something like that:

C:\fakepath

Where, obviously, C:\fakepath gotta be fake, because Macs don't have a C drive. I don't really know the purpose of this box (aside from being a drop point for files), but if it can't display a path, maybe it should display something else?


As Rosinante says below, it seems all browsers return such a fake path. If that's the case, why display the path at all?

In case this doesn't look very obvious to most of the Windows users out there, Safari doesn't display the file path before <input type="file"> elements. This file path box is actually an <input> displayed next to the file upload button, and the developers made the conscious choice to display this fake path string in it.

share|improve this question

marked as duplicate by random Apr 22 '11 at 17:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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, System.io.Path.GetFileName 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; } –  Azhar Shahazad Jan 29 at 19:42

1 Answer 1

This is a browser security feature, not under the control of the site.

share|improve this answer
4  
And Ian Hickson, who is involved in the HTML5 specifications, writes: "The original plan was to just have the filename. Unfortunately, it turns out that if you do that, there are certain sites that break, because they expect the path (and they expect a Windows path, no less). This is why Opera and IE8 return a fake path -- not because HTML5 says to do it. In fact I made HTML5 say it because they were doing it." –  Arjan Apr 22 '11 at 16:48
    
I learned something today, but it doesn't really change the question. If all browsers return a fake path, why display the path at all? –  zneak Apr 22 '11 at 16:50
2  
For example, @zneak, because of hardware firmware expecting it, which could not be easily changed. So: really just because there's too many web sites out there that expect a path, some of which cannot be easily changed. :-( –  Arjan Apr 22 '11 at 16:53
    
@Arjan, now you can post that as an answer :D –  YOU Apr 22 '11 at 16:55
    
I know what @YOU're referring to, but I think this has already been answered just fine! (we could edit it into this answer of course.) –  Arjan Apr 22 '11 at 16:56
    
@zneak, note that the Stack Exchange HTML is really just <input type="file" name="filename" id="filename-input" value="browse" ...>. –  Arjan Apr 22 '11 at 16:57
    
@Arjan No, it's not. On Safari, the file path doesn't show up before an <input type="file">. Stack Exchange developers consciously chose to display the (fake) file path in a box with a layout similar to the one you'd get with Windows. The path element's id is shadow-filename. If you hide it, the file path disappears. –  zneak Apr 22 '11 at 17:00
    
Are you sure, @zneak? I only see this in Chrome, not in other browsers, on the Stack Exchange sites... –  Arjan Apr 22 '11 at 17:02
    
@Arjan Yes, I am. Pick a file, fire up the web inspector, type document.querySelector('#shadow-filename').style.display = 'none' and watch it disappear. –  zneak Apr 22 '11 at 17:03
    
I meant: are you sure all browsers show it to you, @zneak? Not on my Mac. –  Arjan Apr 22 '11 at 17:05
    
@Arjan Firefox doesn't display it, but that's probably for the reasons mentioned in your first link (i.e. it just gives the actual file name when querying for the <input type="file">'s value). Other than that, it works the same way: hide shadow-filename, and you indeed get rid of the file name field. –  zneak Apr 22 '11 at 17:08
2  
Okay, I was wrong about the <input type="file" ...> which is indeed not what is shown when the JavaScript kicks in, @zneak. But why blame the SE sites for displaying the path that the browser gives them...? –  Arjan Apr 22 '11 at 17:10
    
@Arjan I blame SE for using a broken feature of HTML 5. Besides, all browsers already implement some kind of way to tell the user which file they selected. Why did they have to replace it? –  zneak Apr 22 '11 at 17:22
    
Ah, @zneak, I guess I don't use many websites that use plain old <input type="file" ...> but indeed then Chrome would just show the bare file name without its path. (Still then the path as sent to the server would be C:\fakepath, but one would not see it.) I can't say why SE needed to replace it. Maybe because they are not uploading to SE but to imgur.com, but even that could probably be done without the dummy <input> thingies. Or they might just have wanted to have the dialog look the same on every system? (Waffles who answered the duplicate question might know.) –  Arjan Apr 22 '11 at 17:47
    
@zneak, I don't know about your OS, but for windows, do this, 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, System.io.Path.GetFileName 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; } –  Azhar Shahazad Jan 29 at 19:41

Not the answer you're looking for? Browse other questions tagged .