To say the least this debugging has been frustrating, and I don't think the wiskey is going to help.

I've been programming now for 2.5 years so I know more than the average newbie, but I have not been able to figure this one out. Maybe some veterans out there could let me a hand.

Here is the scenario, - I have a pic uploading script located on 2 websites with identical code, on 1 website it works fine, on the other I am getting this error message.

This is the error :

Warning: getimagesize(0) [function.getimagesize]: failed to open stream: No such file or directory in /home/5292/domains/[mywebsite]/html/includes/images.php.lib on line 37

Warning: getimagesize(0) [function.getimagesize]: failed to open stream: No such file or directory in /home/5292/domains/[mywebsite]/html/includes/images.php.lib on line 37
Failed to create thumbnail image: Unable to retrieve image info from file

Here is the code line 37 found in "images.php.lib" (which is an included file within my pic uploading file)

<?php

function CreateScaledImage($file, $maxSize, &$errMsg)
{
$tmpFile = $scaledImage = null;
$errMsg = "";

// Extract image size:
$imageSize = getimagesize($file); :mad: LINE 37
if ($imageSize)
{
// Pull original size:
$gdWidth = $imageSize[0];
$gdHeight = $imageSize[1];
$gdType = $imageSize[2];

// Check to make sure we support this image type:
if (imagetypes() & $gdType)
{
  $oldImage = null;

  switch($gdType)
  {
    case IMAGETYPE_GIF:
      $oldImage = imagecreatefromgif($file); break;
    case IMAGETYPE_JPEG:
      $oldImage = imagecreatefromjpeg($file); break;
    case IMAGETYPE_PNG:
      $oldImage = imagecreatefrompng($file); break;
    case IMAGETYPE_WBMP:
      $oldImage = imagecreatefromwbmp($file); break;

    default:
      $errMsg = "Image type not supported";
  }

  if ($oldImage)
  {
    // Figure out scale factor:
    $scale = ($gdWidth > $gdHeight) ? $gdWidth / $maxSize : $gdHeight / $maxSize;

    // Calc new scaled size:
    $gdNewWidth = round($gdWidth / $scale);
    $gdNewHeight = round($gdHeight / $scale);

    $newImage = imagecreatetruecolor($gdNewWidth, $gdNewHeight);
    $bReturn = imagecopyresampled(
      $newImage, $oldImage, 
      0, 0, 0, 0, 
      $gdNewWidth, $gdNewHeight, $gdWidth, $gdHeight
      );
    if (!$bReturn)
      $errMsg = "Failed to resize image";
    else
      $scaledImage = $newImage;

    // Cleanup:
    imagedestroy($oldImage);
  }
  else
    $errMsg = "Unable to open image file $file";
}
else
  $errMsg = "Image type not supported";

}
else
$errMsg = "Unable to retrieve image info from file"; :eek: ERROR Message that I am getting

if ($scaledImage)
{
$tmpFile = GetTempFilename();
imagejpeg($scaledImage, $tmpFile);
}

return $tmpFile;
}

?>

Can anyone out there offer a glimmer of hope as to why this is working on another website that I host and returning and error on this one?

Maybe there is another solution out there?

I can paste the code for my uploading script as well if needed.

Thanks, - B 🆒

    Find out what the value of $file is within the function. If it is empty or does not look right, then go to the script that calls the CreateScaledImage() function and find out what value it is sending. To start:

    function CreateScaledImage($file, $maxSize, &$errMsg)
    {
       if(!is_readable($file))
       {
          user_error("File '$file' does not exist or is not readable.");
          return false;
       }
       // rest of function
    }
    

      fair enough, when I run this little bit of code :

      $errorCode = $_FILES['form1']['error'];
         echo $errorCode;
         echo "<pre>\n";
         print_r($_FILES); 
         echo "</pre>\n"

      I get this :

      Array
      (
          [userfile] => Array
              (
                  [name] => Array
                      (
                          [0] => 07120701.jpg
                          [1] => 
                          [2] => 
                          [3] => 
                          [4] => 
                          [5] => 
                          [6] => 
                          [7] => 
                          [8] => 
                          [9] => 
                          [10] => 
                          [11] => 
                          [12] => 
                          [13] => 
                      )
      
              [type] => Array
                  (
                      [0] => image/pjpeg
                      [1] => 
                      [2] => 
                      [3] => 
                      [4] => 
                      [5] => 
                      [6] => 
                      [7] => 
                      [8] => 
                      [9] => 
                      [10] => 
                      [11] => 
                      [12] => 
                      [13] => 
                  )
      
              [tmp_name] => Array
                  (
                      [0] => /tmp/php0EewoM
                      [1] => 
                      [2] => 
                      [3] => 
                      [4] => 
                      [5] => 
                      [6] => 
                      [7] => 
                      [8] => 
                      [9] => 
                      [10] => 
                      [11] => 
                      [12] => 
                      [13] => 
                  )
      
              [error] => Array
                  (
                      [0] => 0
                      [1] => 4
                      [2] => 4
                      [3] => 4
                      [4] => 4
                      [5] => 4
                      [6] => 4
                      [7] => 4
                      [8] => 4
                      [9] => 4
                      [10] => 4
                      [11] => 4
                      [12] => 4
                      [13] => 4
                  )
      
              [size] => Array
                  (
                      [0] => 28106
                      [1] => 0
                      [2] => 0
                      [3] => 0
                      [4] => 0
                      [5] => 0
                      [6] => 0
                      [7] => 0
                      [8] => 0
                      [9] => 0
                      [10] => 0
                      [11] => 0
                      [12] => 0
                      [13] => 0
                  )
      
          )
      
      )

      So it looks like that the fileupload.php is working, the original code that I posted in my first post was from the included file "images.php.lib"

      I will try and place that code that you gave me and see if that give me anything...

      BTW there are 14 pics that can be uploaded on my pic upload page that's why the array is so large.

        UPDATE : yes I ran that code you gave me and got the error
        "Notice: File '0' does not exist or is not readable."

        something is not working but I can't figure it out, also that other site I mention that has the exact same code is also hosted on the same server with the same php.ini file - strange

          We'll probably need to see the code where the CreateScaledImage is called, and see how the first parameter to that call is set.

            ah yes, the code for uploading the file is here :

               if (isset($_POST["submit"])) {
                for ($i = 0; $i < count($_FILES["userfile"]["name"]); ++$i) {
                    $errMsg = null;
                    $file["name"] = $_FILES["userfile"]["name"][$i];
                    $file["tmp_name"] = $_FILES["userfile"]["tmp_name"][$i];
                    $file["error"] = $_FILES["userfile"]["error"][$i];
                    $pic_id = SaveImage($file, $errMsg);
                    if ($pic_id) {
                        $row_Recordset1['image'.($i+1)] = $pic_id;
                        $myquery = "UPDATE company_profiles SET image".($i+1)."='$pic_id' WHERE user_id='$userinfo[user_id]'";
                        /* Update records *//////////////
                        // echo "updated $extension<br>";
                        my_query($myquery);
                        echo "<!-- ".GetExternalImageURL($pic_id)." -->\n";
                    }else        {
                      if (strlen(trim($errMsg)))
                        echo "$errMsg<br>\n";
            	}  
            } }

            Same code thats working on the other site too... 😕

              The Strange this is I don't see where the CreateScaledImage function is being called, yet it is running.

                contrasites wrote:

                The Strange this is I don't see where the CreateScaledImage function is being called, yet it is running.

                That's what you'll need to locate, though. If you have several include files, you may need to look inside of them (as well as any files that they include, and so on). You might be able to narrow it down by modifying that error-trapping code with a debug_print_backtrace():

                function CreateScaledImage($file, $maxSize, &$errMsg)
                {
                   if(!is_readable($file))
                   {
                      user_error("File '$file' does not exist or is not readable.");
                      echo "<pre>";
                      print_debug_backtrace();
                      echo "</pre>\n";
                      return false;
                   }
                   // rest of function
                }
                

                  ok, it was located in the same "images.php.lib" file within the SaveImage function, and that SaveImage function is being called in the pic uploading script that I posted just before, I'm looking at the comment "//If no file or error occurred, skip:" it is possible it is returning null? :eek:

                  function SaveImage($file, &$errMsg)
                  {
                    $errMsg = null;
                    $pic_id = null;
                  
                    // If no file or error occurred, skip:
                    if (!strlen($file["name"]) || $file["error"])
                      return null;
                  
                    // Good image, do any scaling and check resulting file sizes:
                    $fullFile = CreateScaledImage($file["tmp_name"], 800, $fullErrMsg);
                    $thumbFile = CreateScaledImage($file["tmp_name"], 120, $thumbErrMsg);
                  
                    if ($fullFile && !$fullErrMsg && $thumbFile && !$thumbErrMsg)
                    {
                      $fullSize = filesize($fullFile);
                      $thumbSize = filesize($thumbFile);
                  
                  if ($pic_id = AddPicRecord($thumbFile, $fullFile, $errMsg))
                    $errMsg = "Failed to load picture into database: $errMsg";
                    }
                  
                    else
                    {
                      if ($fullErrMsg)
                        $errMsg = "Failed to store full size image";
                      if ($thumbErrMsg)
                        $errMsg = "Failed to create thumbnail image: $thumbErrMsg";
                    }
                  
                    // Remove temp files:
                    if ($fullFile && file_exists($fullFile))
                      unlink($fullFile);
                    if ($thumbFile && file_exists($thumbFile))
                      unlink($thumbFile);
                  
                    return $pic_id;
                  }

                    Heh...now you have to find what is calling that SaveImage() function, to find out where it is getting its value for $file. It's sort of like tracking down drug smugglers, except instead of "following the money" you need to "follow the variable". 🙂

                      Write a Reply...