Using HTML POST to upload file via PHP

不想你离开。 提交于 2019-12-08 11:44:33

问题


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";}
?>

and HTML code is:

<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

error uploading file /var/tmp    

I guess file name was not retrieved from html?


回答1:


Error is in enctype:

enctype="multipart/form-data" 

not:

enctype="mutipart/form-data"



回答2:


You have typo mistake in enctype="multipart/form-data" , instead of this you typed enctype="mutipart/form-data" . So "mutipart" spelling is need to correct.



来源:https://stackoverflow.com/questions/45187680/using-html-post-to-upload-file-via-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!