admin管理员组

文章数量:1325756

get selected file path from JavaScript. Hi! I want to get selected file path from JavaScript

<input type="file" class="input-file" id="inputfile" onchange="ReadFile()">

here I want to assign file path to model.

function GetFileProerties() {
    var fileproperties = {
        "FileName": upload.files[0].name,
        "FilePath": ** here i want to assign selected file path ** ,
        "FileType": upload.files[0].name.substr((upload.files[0].name.lastIndexOf('.') + 1)),
        "FileSize": upload.files[0].size,
        "Modified Date": upload.files[0].lastModifiedDate
    }
    return JSON.stringify(fileproperties);
}

get selected file path from JavaScript. Hi! I want to get selected file path from JavaScript

<input type="file" class="input-file" id="inputfile" onchange="ReadFile()">

here I want to assign file path to model.

function GetFileProerties() {
    var fileproperties = {
        "FileName": upload.files[0].name,
        "FilePath": ** here i want to assign selected file path ** ,
        "FileType": upload.files[0].name.substr((upload.files[0].name.lastIndexOf('.') + 1)),
        "FileSize": upload.files[0].size,
        "Modified Date": upload.files[0].lastModifiedDate
    }
    return JSON.stringify(fileproperties);
}
Share Improve this question edited Jun 8, 2018 at 5:44 Hoppeduppeanut 1,1697 gold badges24 silver badges60 bronze badges asked Jun 8, 2018 at 5:06 MathanKumarMathanKumar 1121 gold badge1 silver badge11 bronze badges 4
  • You have "FileType" twice. I think the full path is not available for security reasons. – PepitoSh Commented Jun 8, 2018 at 5:09
  • What do you mean by the FilePath? You mean the path on the local PC? If so, why do you want that? – mjwills Commented Jun 8, 2018 at 5:10
  • I am selecting file from my local drive so i want selected file path – MathanKumar Commented Jun 8, 2018 at 5:14
  • Possible duplicate of <input type=‘file’> for IE gives full path, need file name only – mjwills Commented Jun 8, 2018 at 5:15
Add a ment  | 

2 Answers 2

Reset to default 3

This is not possible in JavaScript due to browser security considerations.

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

Like you, I used <input type="file"...> to allow user to select file they want me to pull data from, and now need to connect with that file to pull the data. My next attempt is bining event listener and loop to grab the file, path after it is selected.

本文标签: how to get selected file path in javascriptStack Overflow