Aravinth E Aravinth E - 1 year ago 204
Javascript Question

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.

czl czl
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download