-2

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");
?>
Norhan
  • 105
  • 2
  • 16
  • I suspect enctype... show us your html. – demux Sep 07 '14 at 02:02
  • 1
    @ArnarYngvason As do I. – John Conde Sep 07 '14 at 02:03
  • Could even be a GET as the form's method or POST not defined as the method, an undefined/unassigned variable; could be anything. Voted to close. – Funk Forty Niner Sep 07 '14 at 02:15
  • 3
    This is why you should not post a question and walk away. This could have been resolved by now. – John Conde Sep 07 '14 at 02:16
  • @JohnConde Thought the same thing ;) – Funk Forty Niner Sep 07 '14 at 02:16
  • It's my first time here, and sorry for this errors. This is just an input name=_postImage in form The form's method is Post and there are no variables in my code. @John Conde I've a problem.I asked here to get help not to close my post and told me to walk away . I know My english is some poor , but it isn't a good way to help. – Norhan Sep 07 '14 at 10:05
  • 2
    @Norhan He did not tell you to walk away. But walk away is what you did. In order for us to help you, you have to provide us with your HTML form. You did not do that 10 hours ago when we asked you to. You should wait and read the comments after you post a question. We like to help, but you have to help us to help you. It would be best in the future if you would always post all of the relevant code (even if you don't think that it is relevant). This might help you: http://stackoverflow.com/questions/15130159/files-empty-after-form-submission?lq=1 – demux Sep 07 '14 at 12:34
  • 1
    @ArnarYngvason ooh, sorry for that. I was very passive because of the closure of my question so sorry again. I did not expect that anyone will answer it so fast. I will focus on these observations next time.And now, i add html code . at all Thanks for reply and the clarification – Norhan Sep 16 '14 at 10:14

1 Answers1

1

It means the tag name attribute does not match the post index, your input needs to be like this:

<input type="file" name="_postImage">
meda
  • 45,103
  • 14
  • 92
  • 122
  • 1
    This may not be the issue. There are other factors that can cause this as well. But we can't tell until they post their HTML. – John Conde Sep 07 '14 at 02:07
  • @Norhan show the full code, where is the submit button and full php – meda Sep 16 '14 at 12:29