2017-05-23 36 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) –

回答

相關問題