How to Get Full Path of Selected File on Change of <Input Type='File'> Using Javascript, Jquery-Ajax

How to get selected file's path in "<input type="file">" in jquery?

You can only get the local name of user selected file in an HTML file input element using the File API.

For security reasons, the path is excluded from this property.

Use jQuery to get the file input's selected filename without the path

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, '')

How to get the full path of the file from a file input

You cannot do so - the browser will not allow this because of security concerns. Although there are workarounds, the fact is that you shouldn't count on this working. The following Stack Overflow questions are relevant here:

  • full path from file input using jquery
  • How to get the file path from HTML input form in Firefox 3

In addition to these, the new HTML5 specification states that browsers will need to feed a Windows compatible fakepath into the input type="file" field, ostensibly for backward compatibility reasons.

  • http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018981.html
  • The Mystery of c:\fakepath Unveiled

So trying to obtain the path is worse then useless in newer browsers - you'll actually get a fake one instead.

How To Get Real Path Of A File Using Jquery

What are you trying to do is not possible due to security reasons.

Also, check this answer: https://stackoverflow.com/a/15201258/706273

Get filename from input [type='file'] using jQuery

You have to do this on the change event of the input type file this way:

$('#select_file').click(function() {
$('#image_file').show();
$('.btn').prop('disabled', false);
$('#image_file').change(function() {
var filename = $('#image_file').val();
$('#select_file').html(filename);
});
});​

How to get selected file name and file path from input type file using jQuery

https://developer.mozilla.org/en-US/docs/Web/API/File/name

Returns the name of the file represented by a File object. For security reasons, the path is excluded from this property.

you can get the fileName but not path.

Preview an image before it is uploaded