2017-05-23 37 views
0

我的代码文件名正确到达,但文件目录不来。如何从输入类型文件中使用jQuery获取选定的文件名和文件路径

我的代码

<!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> 

如何解决这个问题。请帮我解决这个问题。 谢谢。

+0

您将得到与文件名,大小,扩展名等有关的其他详细信息。请参阅https://codepedia.info/get-file-name-size-type-count-in-jquery-input-file-file-api/ –

+0

出于安全原因,您无法获取文件路径,但名称仅在此处显示示例http://jsfiddle.net/ismailfarooq/fyajtamb/ –

+0

[如何获取使用javascript,jquery-ajax?](https://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-使用-JAV) –

回答

相关问题