I want to access file path obtained from browsing file using input tag. I want to display the path.
-
eh, darn, clicked the wrong duplicate link, but this is a duplicate How to get full path of selected file on change of <input type=‘file’> using javascriptBrigand– Brigand2013-08-17 09:12:26 +00:00Commented Aug 17, 2013 at 9:12
-
possible duplicate of How to write the Path of a file to upload in a text box?Matthew Riches– Matthew Riches2013-08-17 09:14:36 +00:00Commented Aug 17, 2013 at 9:14
-
possible duplicate of Can I use any HTML or JavaScript API to get the file's path in input[type=file]?Jonathan Naguin– Jonathan Naguin2013-08-17 09:20:22 +00:00Commented Aug 17, 2013 at 9:20
Add a comment
|
2 Answers
Here is an example using jquery:
<input type="file" id="input" />
$(document).ready(function() {
$("#input").on("change", function() {
alert($(this).val());
});
});
I.e. $(this).val() contains the file path.
Here is a jsfiddle example http://jsfiddle.net/krasimir/uwaf2/
Comments
From
Use jQuery to get the file input's selected filename without the path
$('input[type=file]').val()
var filename = $('input[type=file]').val().split('\\').pop();or you could just do (because it's always C:\fakepath that is added for security reasons):
var filename = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '')
Full path from file input using jQuery
You cannot read the full file path in js due to security reasons.
1 Comment
fredden
Is it "C:\fakepath\" on platforms other than Windows? I'd find it odd to see that path on Linux or Mac.