Reputation: 1720
I display a file open box so the user can select a file on their computer:
<input type="file" id="upload_input"/>
but when I get the file the user chose in Javascript (see code below), which I believe is 'safe' since javascript executes on the client side -- all I get is the file, not the full path -- despite the fact that the full path and filename appear in the field next to the 'Browse' button that input type=file always gives you.
In other words the user selects a file located on his machine for example at c:/aFolder/thefile.rtf. Then after choosing that file the full path appears in the field next to the 'Browse' button: c:/aFolder/thefile.rtf
Yet when I programmatically retrieve the value of that field, the entire path is stripped off and all I have is the filename:
filename = document.getElementById('upload_input').value;
alert("The selected file name is " + filename);
Why does the input type=file control even bother to show the user the full path if you can't get it programmatically? It's all happening on the client side after all, it's not like this is a full path on the server.
One other question: I use the filename above and construct a fully qualified path to that file, only for the sake of getting my JWplayer code working. The full path I create for development here is temporary.
In otherwords, when I get the filename above, I do this:
vidFname = ("c:/xampp/htdocs/theWebsite/aFolder/" + filename);
alert("The full path is: " + vidFname);
and then I try to play the video in Jwplayer:
playlist = { file: vidFname };
theJwPlayer().load(playlist);
theJwPlayer().play(true);
but Jwplayer gives me "Permission denied or file not found."
Here is what I had to change to get this to work:
vidFname = ("http://localhost/theWebsite/aFolder/" + filename);
alert("The full path is: " + vidFname);
playlist = { file: vidFname };
theJwPlayer().load(playlist);
theJwPlayer().play(true);
By changing the path to my localhost the above code works -- the video loads and succesffully plays.
NOTE: I don't think this is a 'folder permissions' issue because I can play the exact same file in the same location with a different .FLV player (standalone) app on my computer. So it's not folder permissions in my c:/xampp that's making Jwplayer say 'permission denied or file not found.'
Why won't Jwplayer (or is it Javascript..?) not letting me use a fully-qualified pathname to the file when I call jwplayer().load() ?
After all, I'm using 'theJwPlayer' in Javascript,' which is running on the client computer, and the file is on the client computer too, so it's not a security issue.
Or is there something I'm missing here? NOTE: I fully apologize if this question is ignorant but at my current level of web programming, which you may have passed LONG ago, this is puzzling, ESPECIALLY the jwplayer().load() not working with a fully qualified path name.
Upvotes: 2
Views: 1385
Reputation: 413720
Browsers will not reveal actual file paths to JavaScript code. It's a security thing. You won't be able to get at local files without using the (new, only available in new browsers) HTML5 file handling APIs, and even those won't give you complete file pathnames.
Similarly, when the file input is submitted with a form, the server won't get the full path either.
I think it's not very likely that this media player tool you're working with is designed to work with local files (that is, files on the local file system where the browser is running).
Upvotes: 2