使用HTML POST通过PHP上传文件 [英] Using HTML POST to upload file via PHP

查看:394
本文介绍了使用HTML POST通过PHP上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用HTML POST方法和PHP将本地文件上传到Web服务器. 这是我的php代码:

I am trying to upload a local file to webserver using HTML POST method and PHP. this is my php code:

<?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"] ["error"]显示为0,通过运行这段代码我得到

$_FILES["rawexcel"]["error"] shows 0 and from running this peice of code i get

error uploading file /var/tmp    

我想没有从html检索到文件名?

I guess file name was not retrieved from html?

推荐答案

enctype中出现错误:

Error is in enctype:

enctype="multipart/form-data" 

不是:

enctype="mutipart/form-data"

这篇关于使用HTML POST通过PHP上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆