2017-07-19 91 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”拼写是需要更正的。