PHP Post data not received

Viewed 490

i'm currently working on a small script for my Homepage but i ran into a problem.

I Try to upload an Image, but it seems like the POST data from the form is not being received. What did i do wrong?

I already changed the post_max_size and everything in the php.ini.

These are the Errors i get:

"Notice: Undefined index: image in ...." & "Notice: Undefined index: submit in ...."

 <form method="POST" action="/eye/sites/handling/post.php" enctype="multipart/form-data">
     <div class="fileUpload">
        <span><i class="fa fa-folder-o" aria-hidden="true"></i> Bild wählen</span>
    <input type="file" class="upload" name="image"/>
    </div>
    <input type="submit" value="Upload It!" name="submit"/>
 </form>

<?php session_start();
error_reporting(E_ALL);
if (isset($_SESSION["login_stat"])) {
date_default_timezone_set('Europe/Berlin');
$config = "$_SERVER[DOCUMENT_ROOT]/eye/more/config.xml";
$xml = simplexml_load_file($config);
$picWidth = $xml->pic->width;
$picHeight = $xml->pic->height;
$fulldate = date('dmYHis');
if(isset($_POST["submit"])) {
  if (file_exists($_FILES['image']['tmp_name']) || is_uploaded_file($_FILES['image']['tmp_name'])) {
    $typeCheck = $_FILES['image']['type'];
    if ($typeCheck != "image/jpeg") {
      $error = "Not a .jpg";
      header('location: /eye/sites/post.php?stat=bad&error='.$error);
      exit;
    }
    $file = $_SERVER['DOCUMENT_ROOT']."/uploads/".$fulldate.".jpg";
    $type = "image/jpeg";
    move_uploaded_file($_FILES['image']['tmp_name'], $file);
    $file_thmb = $_SERVER['DOCUMENT_ROOT']."/uploads/!1A_thmb/".$fulldate.".jpg";
    include "resize-class.php";
    $resizeObj = new resize($file);
    $resizeObj->resizeImage($picWidth, $picHeight, 'crop');
    $resizeObj->saveImage($file_thmb, 100);
    // header('location: /eye/sites/post.php?stat=good');
  } else{
  // header('location: /eye/sites/post.php?stat=bad&error=No File');
  }
} else{
  // header('location: /eye/sites/post.php?stat=bad&error=No Data');

  echo  $_SERVER['CONTENT_TYPE'];
  echo "<br>";
  echo $_FILES['image']['tmp_name'];
  echo "<br>";
  echo $_POST['submit'];
  echo "<br>";

}
} else {
header('location: /eye/index.php?stat=in');
}
?>

Edit: The problem is definitely about my Localhost. This whole thing is working fine on my Webspace, but on my localhost it's not working. BUT: I'm not getting errors anymore, when is click on Submit it goes to the php file that should save the image, but nothing is happening. I just see a white Page. But like i said, it runs perfectly on my webspace..

2 Answers

If this is running on your local machine, do a quick check to make sure your "php.ini" file is configured to allow file uploads.

php.ini

file_uploads = On

The codes look fine. Check if your form action is posting to the correct path and if I may suggest using a simpler approach to test your file upload function before making it more complex. Use the following to start testing.

if (isset($_POST["submit"])) {
    if (file_exists($_FILES['image']['tmp_name']) || is_uploaded_file($_FILES['image']['tmp_name'])) {
        echo "Upload is working!";
    }
} 

Keep us updated on your findings.

Perhaps this general information will help someone, as it helped me: a submitted form will only include fields that have defined 'name' attributes. 'id' is not enough.

The idea is that 'id' identifies an element in the DOM for use by JavaScript (either as a global variable or for use in document.getElementById(ID)), but 'name' identifies those elements whose names and values will be sent to the destination ('action') page.

So it makes sense that there are two different identifying attributes, used in two different ways.

Related