I have a php code to upload image as a file, it gave me the following error:
Notice: Undefined index: _postImage in E:\xampp\htdocs\paperblog\Admin\AddNewPost.php on line 18
and line 18 is :
move_uploaded_file($_FILES['_postImage']['tmp_name'],$_SERVER['DOCUMENT_ROOT']."\paperblog\Post_Imges\a.jpg");
my php version: PHP/5.5.9
, file uploads in php.ini
is on
what is wrong here? I tried to solve it in several ways, but it still gives me the same error
Html code :
<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 code :
<?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");
?>