0

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.

Aravinth E
  • 449
  • 2
  • 6
  • 29
  • you cannot get file path for security reason but name only see example here http://jsfiddle.net/ismailfarooq/fyajtamb/ – Ismail Farooq May 23 '17 at 08:32
  • Possible duplicate of [How to get full path of selected file on change of using javascript, jquery-ajax?](https://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav) – Ismail Farooq May 23 '17 at 08:33

1 Answers1

3

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.

czl
  • 117
  • 3