How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?

后端 未结 11 2626
谎友^
谎友^ 2020-11-21 04:36

How to get full path of file while selecting file using




        
11条回答
  •  星月不相逢
    2020-11-21 05:06

    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);
    });
    

    http://jsfiddle.net/SCK5A/

    So don't waste your time.

    edit: If you need the file's path for reading a file you can use the FileReader API instead. Here is a related question on SO: Preview an image before it is uploaded.

提交回复
热议问题