javascript 如何在javascript中获取选定的文件路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50753700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:15:31  来源:igfitidea点击:

how to get selected file path in javascript

javascript

提问by MathanKumar

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

从 JavaScript 获取选定的文件路径。你好!我想从 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);
}

回答by Hoppeduppeanut

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

出于浏览器安全考虑,这在 JavaScript 中是不可能的。

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

另请参阅:如何在更改<input type=‘file'>使用 javascript、jquery-ajax 时获取所选文件的完整路径?

回答by Ipse

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 combining event listener and loop to grab the file, path after it is selected.

像您一样,我曾经<input type="file"...>允许用户选择他们希望我从中提取数据的文件,现在需要与该文件连接以提取数据。我的下一个尝试是结合事件侦听器和循环来获取文件,选择后的路径。