简体   繁体   中英

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

Returns the name of the file represented by a File object. For security reasons, the path is excluded from this property.

you can get the fileName but not path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM