0

I want to access file path obtained from browsing file using input tag. I want to display the path.

Steve Hanov
  • 11,316
  • 16
  • 62
  • 69
priyanka
  • 1
  • 2
  • eh, darn, clicked the wrong duplicate link, but this is a duplicate [How to get full path of selected file on change of using javascript](http://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav) – Brigand Aug 17 '13 at 09:12
  • possible duplicate of [How to write the Path of a file to upload in a text box?](http://stackoverflow.com/questions/4640082/how-to-write-the-path-of-a-file-to-upload-in-a-text-box) – Matthew Riches Aug 17 '13 at 09:14
  • possible duplicate of [Can I use any HTML or JavaScript API to get the file's path in input\[type=file\]?](http://stackoverflow.com/questions/10084133/can-i-use-any-html-or-javascript-api-to-get-the-files-path-in-inputtype-file) – Jonathan Naguin Aug 17 '13 at 09:20

2 Answers2

0

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/

Krasimir
  • 13,306
  • 3
  • 40
  • 55
0

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.

Community
  • 1
  • 1
mithuntnt
  • 507
  • 1
  • 5
  • 17
  • Is it "C:\fakepath\" on platforms other than Windows? I'd find it odd to see that path on Linux or Mac. – fredden Aug 17 '13 at 09:24