Home > other >  How to get the file's path from file input?
How to get the file's path from file input?

Time:02-07

please tell me how to get a full file path from an <input type="file">

i have tried fileinput.value but it shows fakepath.

i have also tried mozFullPath.

CodePudding user response:

For security reasons browsers do not allow this, i.e. JavaScript in browser has no access to the File System, however using HTML5 File API, only Firefox provides a mozFullPath property, but if you try to get the value it returns an empty string:

$('input[type=file]').change(function () {
    console.log(this.files[0].mozFullPath);
});

https://jsfiddle.net/SCK5A/

CodePudding user response:

Due to major security reasons, most browsers don't allow getting it so JavaScript when ran in the browser doesn't have access to the user file system. having said that, the Firefox is exceptional and provides the mozFullPath property but it will only return an empty string.

  •  Tags:  
  • Related