Page 1 of 1

Photoalbum ZIP problem

Posted: Tue May 16, 2006 4:49 am
by scribeke
I'm looking for a solution now for about 2 days and I'm getting quite desperate.
I already posted this problem on other fora but no one seems to know the answer.
I hope you guys are smarter then me & them :)

The problem is with uploading a picture

My script can either upload a JPEG or a ZIP with JPEGS

With a single JPEG the script doesn't have a problem, the JPEG is put in the folder img/temp, after that the image is copied to img/ with BIG_ before the name, then it is copied to img/ with SMALL_ before the name, that last image is then resized with the function resize_jpg

With a zipfile my script turns an error, the zip is unzipped in img/temp, the zipfile itself is deleted, the imagefiles are put with BIG_ and SMALL_

But when resizing there's a problem, the filename is given and is received in the same way as with a single JPEG but then it won't take the image size

I don't see a difference with a single JPEG but for some reason with a ZIP it can't read the filesize...


Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?
set_error_handler('oops');

function oops($type, $msg, $file, $line, $context) {
    echo "<h1>Error!</h1>";
    echo "An error occurred while executing this script. Please contact the <a href=mailto:webmaster@somedomain.com>webmaster</a> to report this error.";
    echo "<p />";
    echo "Here is the information provided by the script:";
    echo "<hr><pre>";
    echo "Error code: $type<br />";
    echo "Error message: $msg<br />";
    echo "Script name and line number of error: $file:$line<br />";
    $variable_state = array_pop($context);
    echo "Variable state when error occurred: ";
    print_r($variable_state);
    echo "</pre><hr>";
}

function resize_jpg($img,$w,$h)
    {
   $imagedata = getimagesize($img);
   echo "IMG : $img <br />";
   echo "IMGSIZE : $imagedata[0] $imagedata[1]";
   echo "<br /><br />";
   if ($w && ($imagedata[0] < $imagedata[1]))
        {
        $w = ($h / $imagedata[1]) * $imagedata[0];
        }
   else
           {
        $h = ($w / $imagedata[0]) * $imagedata[1];
           }
   $im2 = ImageCreateTrueColor($w,$h);
   $image = ImageCreateFromJpeg($img);
   imagecopyResampled ($im2, $image, 0, 0, 0, 0, $w, $h, $imagedata[0], $imagedata[1]);
   ImageJpeg($im2, $img, 100);
   }

//Een while lus zodat we met break kunnen werken
while(TRUE){

include('connection.php');

//We halen het bestand op
$bestand = $_FILES['picture'];

if(!isset($_FILES['picture']))    //Als er geen plaatje is meegegeven annuleren we de toevoeging
   {
      print("Geen plaatje ingevoerd!<br />");
      break;                        //We stoppen de whilelus
   }

//Controleren of het van het type JPEG is

if($_FILES['picture']['type'] == "image/jpeg" ||  $_FILES['picture']['type'] == "image/pjpeg"){
            $temptype = @$HTTP_POST_FILES['picture']['type'];
         print("");
}
else{
           $temptype = @$HTTP_POST_FILES['picture']['type'];
         if($temptype != "application/x-zip-compressed" && $temptype != "application/zip"){
            print("Alleen JPEGs en ZIPs worden ondersteund!<br />");
            break;
         }
}
   
//We kopieƫren de file
$name = $_FILES['picture']['name'];
if($temptype == "application/x-zip-compressed" || $temptype == "application/zip"){
   $bestemming = "img/temp/" . $name;
   $bool[] = copy($_FILES['picture']['tmp_name'],$bestemming);
   shell_exec("unzip img/temp/$name -d img/temp/");
   unlink("img/temp/" . $name);
}
else {
   $bestemming = "img/temp/" . $name;
   $bool[] = copy($_FILES['picture']['tmp_name'],$bestemming);
}

$handle=opendir('./img/temp/');
while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") {
      echo "$file";
      echo "<br />";
      //we kopieƫren het kleine plaatje
      $bestemmingSMALL = "./img/small_" . $file;
      $bool[] = copy($_FILES['picture']['tmp_name'],$bestemmingSMALL);
      //Er is een plaatje meegegeven. We maken er nu een thumbnail.
         if ($handle2 = opendir('.')) {
       while (false !== ($file2 = readdir($handle2))) {
        if ($file2 != "." && $file2 != "..") {
            echo "$file\n <br />";
        }
       }
       closedir($handle2);
      }
      resize_jpg("./img/small_" . $file,160,120);
            
      $bestemmingBIG = "./img/big_" . $file;
      $bool[] = copy($_FILES['picture']['tmp_name'],$bestemmingBIG);
   }
}
closedir($handle);



//Controleren of alles gelukt is
if(in_array(FALSE,$bool))
            {
            print("Er is een probleem opgetreden met het uploaden van de plaatjes. Contacteer de webmaster.<br />");
            break;
            }

//toevoegen in de database
$sql = "INSERT INTO fotos (ID, PADBIG, PADSMALL) VALUES('','" .$bestemmingBIG . "','" .$bestemmingSMALL . "')";
$result = mysql_query($sql);
     if(!$result)
            {
            print("Probleem met toevoegen foto's aan de database!<br />");
            break;
            }
print("<b>Foto succesvol toegevoegd!</b><br />");

break;

}

?>
</body>
</html>

Posted: Wed May 17, 2006 3:44 am
by scribeke
Come on, does no one know the answer to my problem ??

That can't be ...