简体   繁体   English

使用HTML POST通过PHP上传文件

[英]Using HTML POST to upload file via PHP

I am trying to upload a local file to webserver using HTML POST method and PHP. 我正在尝试使用HTML POST方法和PHP将本地文件上传到Web服务器。 this is my php code: 这是我的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";}
?>

and HTML code is: 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"]["error"] shows 0 and from running this peice of code i get $ _FILES [“ rawexcel”] [“ error”]显示为0,通过运行这段代码我得到了

error uploading file /var/tmp    

I guess file name was not retrieved from html? 我猜没有从html检索到文件名?

Error is in enctype: enctype错误:

enctype="multipart/form-data" 

not: 不:

enctype="mutipart/form-data"

You have typo mistake in enctype="multipart/form-data" , instead of this you typed enctype=" mutipart /form-data" . 您在enctype =“ multipart / form-data”中输入错误,而不是您输入了enctype =“ mutipart / form-data” So " mutipart " spelling is need to correct. 因此,需要更正“ mutipart ”的拼写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM