Chris,
It sure sounds like your server isn't letting the script rename 0.jpg to 1.jpg etc. The only thing I can think of is to check your server permissions. Here's the script as running successfully for me. Maybe someone else will have an idea.
<?php
// 2007 by Jim McMurry jmcmurry@mwt.net jcweather.us
// Place this file in the same folder as wasp2.png. Make sure you have the correct permissions. I used CMOD 777 for the folder.
$filedir = $_SERVER['DOCUMENT_ROOT'] . "/lightning/"; //Subdirectory below your web "root" where files are located.
$numfiles = 10; // number of images to maintain
$ftype = '.png'; // Change to .png/.jpg as desired
// The next 3 only if producing .jpg files
$thumbx = 660; //Width of new image. Reduce if you wish a smaller product.
$thumby = 580; //Height of new image. "
$quality = 95; // For jpg's .. Adequate & reduces file size. Can't go above 99!
//Routine Begins
$origimg = imagecreatefrompng('wasp2.png');
$newimg = imagecreatetruecolor($thumbx, $thumby);
imagecopyresampled($newimg, $origimg, 0, 0, 0, 0, $thumbx, $thumby, 660, 580);
switch ($ftype):
case '.jpg':
imagejpeg($newimg, '0.jpg', $quality);
break;
case '.png':
imagepng($newimg, '0.png');
break;
endswitch;
imagedestroy($newimg); // destroy the images
imagedestroy($origimg);
// Now re-order them
$targetfil = $filedir . $numfiles . $ftype;
if (file_exists($targetfil)) { //If oldest file exists delete it
unlink($targetfil);
}
for($i = $numfiles; $i > 0; $i--){ //cycle through files renaming them
$targetfil = $filedir . $i . $ftype;
$t = $i - 1;
$nextfil = $filedir . $t . $ftype;
if (file_exists($nextfil)) {
rename($nextfil, $targetfil);
}
}
?>
New baby yet?
- Jim