【发布时间】:2015-07-12 03:45:00
【问题描述】:
我想用 php 和 msqli 在我的 phpMYadmin 中上传图片,但是遇到了上面提到的错误,所以几乎所有东西都会插入,除了图片。我认为每件事都很好,不知道问题出在哪里,请帮忙:(
这里是 php:
<?php
if(isset($_POST['submit'])){
$Name=$_POST['Name'];
$Desc=$_POST['Desc'];
$Image=$_FILES['image']['tmp_name']; //get error in this line
echo $_FILES['image']['error'];//get error in this line
$sql="INSERT INTO `items`(`Name`,`Description`, `image`)
VALUES('$Name','$Desc','$Image')";
if(mysqli_query($con,$sql)){
echo "new record";
}
else{echo"Wrong";}
mysqli_close($con);
}
?>
html:
<form action="http://localhost/onlinesShop/newitem.php" method="POST" >
<table id='table_admin'>
<tbody>
<tr>
<td width="116" height="50" align="left">Name</td>
<td width="466"><input name="Name" type="text" id="Name" title="Name" maxlength="200"></td>
</tr>
<tr>
<td height="290">Description</td>
<td><textarea name="Desc" cols="40" rows="15" id="textarea"></textarea></td>
</tr>
<tr>
<td>Image</td>
<td width="80"><input type="file" name="image" id="fileField" ></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Upload"></td>
</tr>
</tbody>
</form>
</table>
</div>
【问题讨论】:
-
需要在
<form>内添加enctype="multipart/form-data"。检查@Ghost 答案它会工作 -
不,我再次收到错误@NarendraSisodia