Hello people,

I am creating thumbnails from images that get uploaded when a user submits.

The thumb is created and stored onto the server in the proper location, BUT when I go in to edit or change an image, the original image gets overwritten when a new image is uploaded, but the new thumb doesn't overwirte the old thumb. It's gives out this error:

Warning: imagejpeg() [function.imagejpeg]: Unable to open '/mydirectory/thumbs/110.jpg' for writing in /mydirectory/title_adder.php on line 62

All directories are chmod'd correctly. I can't figure it out. Any help is appreciated. here's the part of my script that creates the thumbnails:

//if a file was uploaded
$file_name = "$ID.jpg";
if( @copy($file, "/mydirectory/$file_name") )
{  
$iname="$file"; $x=60; $y=89; $srcimage = ImageCreateFromJPEG ($iname); $newimage = imagecreatetruecolor ($x, $y); imagecopyresized ($newimage, $srcimage, 0, 0, 0, 0, $x, $y, imagesx($srcimage), imagesy($srcimage)); imagejpeg($newimage,"/mydirectory/thumbs/$ID.jpg",100); //delete the temporary uploaded image unlink($file); }

    Try chmodding the file, and PLEASE destroy your images after you use them (imagedestroy()). It's very, very bad programming ethic to leave the memory for these things allotted.

      Thank for the advice.

      Now, how do I pull it off? 🙂

      Is there a way to chmod the files when they get created? Just as well, where would imagedestroy() go?

      Thanks for the help.

        $file_name = "$ID.jpg";
        if( @copy($file, "/mydirectory/$file_name") )
        {  
        chmod("/mydirectory/$file_name",777); $iname="$file"; $x=60; $y=89; $srcimage = ImageCreateFromJPEG ($iname); $newimage = imagecreatetruecolor ($x, $y); imagecopyresized ($newimage, $srcimage, 0, 0, 0, 0, $x, $y, imagesx($srcimage), imagesy($srcimage)); imagejpeg($newimage,"/mydirectory/thumbs/$ID.jpg",100); imagedestroy($srcimage); imagedestroy($newimage); //delete the temporary uploaded image unlink($file); }
          Write a Reply...