Aravinth E
Aravinth E

Reputation: 491

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.

Upvotes: 0

Views: 5233

Answers (1)

czl
czl

Reputation: 117

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.

Upvotes: 3

Related Questions