What I'm doing is pretty traditional stuff.
Graphic designer uploads jpg into products/master directory
I've written a 404 handler to look for .jpgs in the master directory resize them & output them to the browser - saving the resized image into products so I don't need to keep creating the images on the fly every time.
code follows - the problem I have is the following. If I don't save the image the 404 handler just keeps working beautifully. If I get the script to save the image down to the products directory it works - twice. Then every subsequent request fails UNTIL I upload the script to the server which resets the process so I can create another 2 images. What am I missing?
Code: Select all
/* $last is the name of the jpg to be created e.g. test.jpg with no directory information */
header("Content-type: image/jpg");
$img_orig = imagecreatefromjpeg('../products/master/'.$last);
$new_x = imagesx($img_orig) / 2;
$new_y = imagesy($img_orig) / 2;
$img_dest = imagecreatetruecolor($new_x,$new_y);
imagecopyresampled( $img_dest,
$img_orig,
0,0,0,0,
$new_x,
$new_y,
imagesx($img_orig),
imagesy($img_orig));
/* This line only works two or three times through - and I've used different ways of defining the filename */
// imageJPEG($img_dest,'../products/'.$last,88);
// this line works at least 8 -10 times
imageJPEG($img_dest,'',88);
ImageDestroy($img_orig);
ImageDestroy($img_dest);