简体   繁体   English

如何使用jQuery从输入类型文件中获取选定的文件名和文件路径

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

my code file name properly coming but file directory does not come. 我的代码文件名正确到来,但是文件目录没有到来。

my code 我的密码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Get Selected File Name</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('input[type="file"]').change(function(e){
            var fileName = e.target.files[0].dir;
            alert('The file "' + fileName +  '" has been selected.');
        });
    });
</script>
</head>
<body>
    <form>
        <input type="file">
    </form>
</body>
</html>

how to solve this problem. 如何解决这个问题呢。 please help me solve this. 请帮我解决这个问题。 thanks. 谢谢。

https://developer.mozilla.org/en-US/docs/Web/API/File/name https://developer.mozilla.org/zh-CN/docs/Web/API/文件/名称

Returns the name of the file represented by a File object. 返回由File对象表示的文件的名称。 For security reasons, the path is excluded from this property. 出于安全原因,该路径从此属性中排除。

you can get the fileName but not path. 您可以获取文件名,但不能获取路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用获取所选文件的完整路径<Input Type=“file” /> - How to get a full path of a selected file using <Input Type=“file” /> 如何在更改时获取所选文件的完整路径<input type="‘file’">使用 javascript,jquery-ajax? - How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax? 如何删除未选择的文件,并在输入类型文件中使用jquery成功上传文件名 - how to remove no file selected and place the file name which is uploaded successfully using jquery in input type file 如何使用jquery从中获取所有文件的名称和大小<input type=file multiple> - How to get all files name and size using jquery from <input type=file multiple> 获取在 HTML 输入中选择的文件的绝对文件名而不是路径 - Get absolute file name of the file selected in HTML input instead of path 如何使用javascript中的输入类型文件获取文件的完整路径? - How to get full path of file using input type file in javascript? 如何在输入文件中获取所选路径? - How to get the selected path in the input file? 如何使用JS和input [type =“ file”]获取文件的名称和大小 - How to get name and size of file using JS and input[type=“file”] 更改输入类型文件选择的名称文件 - Change name File selected by input type file 如何使用jQuery获取用户选择文件的类型? - How to get type of user selected file with jQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM