我有一个PHP代码将图像上传为文件,它给了我以下错误:
注意:未定义的索引:第18行的E:\ xampp \ htdocs \ paperblog \ Admin \ AddNewPost.php中的_postImage
和第18行是:
move_uploaded_file($_FILES['_postImage']['tmp_name'],$_SERVER['DOCUMENT_ROOT']."\paperblog\Post_Imges\a.jpg");
我的php版本:PHP/5.5.9
,php.ini
中的文件上传已打开
这里有什么问题? 我尝试用几种方法解决它,但它仍然给我同样的错误
Html代码:
<form action="AddNewPost.php" method="post" id="cmntfrm" enctype= "multipart/form-data">
<table width="600" border="0" align="center">
<tr>
<td>Post Image :</td>
<td><input name="_postImage" type="file"/></td>
</tr>
<tr>
<td></td>
<td><input name="_PostSubmit" type="submit" value="Save" id="submit" /></td>
</tr>
</table>
</form>
php代码:
<?php
include_once("..\DB.php");
$title="";
$subtitle="";
$details="";
$msg="";
if(isset($_POST['_PostSubmit']))
{
$title=$_POST['_PostTitle'];
$subtitle=$_POST['_PostSubTtile'];
$details=$_POST['_PostDetails'];
$query=" insert into
post(Title,SubTitle,PostDetails,PDay,PMonth,PYear)
values('$title,'$subtitle','$details'".date("d").",".date("m").",".date("Y").")";
$msg="Post added" ;
mysql_query($query);
if($_FILES['_postImage']['tmp_name']!="none" )
{
move_uploaded_file($_FILES['_postImage'] ['tmp_name'],$_SERVER['DOCUMENT_ROOT']."\paperblog\Post_Imges\a.jpg");
$msg.="<br/> Image uploaded Successfully";
}
else
$msg.="<br/> Image File too large or No Image File";
}
include_once("Header.php");
?>
答案 0 :(得分:1)
这意味着标签名称属性与帖子索引不匹配,您的输入必须如下:
<input type="file" name="_postImage">