0

I'm trying to upload an image and changing its size and quality and then saving this new modified image into a "images" directory. The PHP logic lives in php/images.php.

I keep getting the following error:

Notice: Undefined index: file in /Applications/XAMPP/xamppfiles/htdocs/invoices/php/logos.php on line 4

Notice: Undefined index: file in /Applications/XAMPP/xamppfiles/htdocs/invoices/php/logos.php on line 5

I've searched around for similar issues, and tried a few of the recommendations, but nothing has worked. I also increased XAMPP's upload file, and that did not work either. Here is the code:

HTML - root_dir/file.html

<form action="php/images.php" enctype="multipart/form-data" id="settingsForm" method="post">
  <label class="settingsLabel" for="img">Upload Your Logo:</label>
  <input name="img" type="file" id="img">
  <input type="submit" id="addImage" name="addImage" value="Add Image">
 </form>

PHP - root_dir/php/images.php

if ( isset($_POST['addImage']) ) {
    $post_photo = $_FILES['file']['name'];
    $post_photo_tmp = $_FILES['file']['tmp_name'];

    $ext = pathinfo($post_photo, PATHINFO_EXTENSION);  // getting image extension

// checking image extension
    if( $ext=='png' || $ext=='PNG' || $ext=='jpg' || $ext=='jpeg' || $ext=='JPG' || $ext=='JPEG' || $ext=='gif' || $ext=='GIF' ) {

        if($ext=='jpg' || $ext=='jpeg' || $ext=='JPG' || $ext=='JPEG') {
            $src=imagecreatefromjpeg($post_photo_tmp);
        }

        if($ext=='png' || $ext=='PNG') {
            $src=imagecreatefrompng($post_photo_tmp);
        }

        if($ext=='gif' || $ext=='GIF') {
            $src=imagecreatefromgif($post_photo_tmp);
        }

        list($width_min,$height_min)=getimagesize($post_photo_tmp); // fetching original image width and height

        $newwidth_min=250; // set compressing image width
        $newheight_min=($height_min / $width_min) * $newwidth_min; // equation for compressed image height
        $tmp_min = imagecreatetruecolor($newwidth_min, $newheight_min); // create frame  for compress image

        imagecopyresampled($tmp_min, $src, 0,0,0,0,$newwidth_min, $newheight_min, $width_min, $height_min); // compressing image
        imagejpeg($tmp_min,"logos/".$post_photo,80); //copy image in folder//
     }
 } else {
     echo "Please choose a file to Upload.";
 }

Anyone know what could be the issue?

Sergio
  • 792
  • 3
  • 10
  • 35

0 Answers0