2017-07-19 93 views
0

我想使用HTML POST方法和PHP將本地文件上傳到網絡服務器。 這是我的PHP代碼:使用HTML POST通過PHP上傳文件

<?php 


if (isset($_POST["submit"])) { 
$updir = "/var/tmp/"; 
$upfile = $updir.basename($_FILES['rawexcel']['name']); 

if(is_uploaded_file ($_FILES ["rawexcel"]["tmp_name"])) 
{ 
move_uploaded_file ($_FILES["rawexcel"]["tmp_name"], $upfile); 

} else {echo "error uploading file ".$upfile;} 
} else {echo "not isset post method";} 
?> 

和HTML代碼是:

<div class="container" id="upl"> 
<h4> Upload files</h4> 
<form action="upl.php" enctype="mutipart/form-data" method="post"> 
<p> upload your files to DB</p> 
<p><input type="file" name="rawexcel" id ="rawexcel"> 
<input type ="submit" value="Upload" name ="submit"></p> 
</form> 
</div> 

$ _FILES [ 「rawexcel」] [ 「錯誤」]表示0和運行這個代碼peice的我得到

error uploading file /var/tmp  

我猜文件名是不是從HTML檢索?

+2

你正在得到什麼錯誤......? – GYaN

+1

更新的問題。總之 - 不能獲得文件名,$ upfile只有$ updir – upicik

+1

upvotes on typo? *哇* –

回答

3

錯誤是在加密類型:

enctype="multipart/form-data" 

不是:

enctype="mutipart/form-data" 
1

你有錯字錯在ENCTYPE = 「的multipart/form-data的」,而不是此鍵入ENCTYPE = 「mutipart/form-data」。所以「mutipart」拼寫是需要更正的。