Hi,
I've got a script to create thumbnails and an xml file listing them for a flash gallery. It works fine on my home server, and runs fine on the production server for smaller amounts of files. Problem is that it needs to be able to handle upwards of 500 files.
I know you're already thinking it's timing out but I've got the code
set_time_limit(360);
at the top of the page, so it shouldn't be that unless 1&1 (not my choice of host!) are overriding it.
Here's the script... I included lots of reporting to find out just where it's breaking:
//start code for generating files
//call image resizing script
require_once('resizeimage.php');
//getting folder name from post variable
$albumf= getcwd().'/../galleries/'.$_POST['folder'];
//set thumbnail height here:
$thumbh='80';
//
echo 'made thumbs folder and left permissions open<br />';
if (!file_exists($albumf.'/thumbs')) {
mkdir($albumf.'/thumbs');
chmod ($albumf.'/thumbs', 0777);
}
echo 'read photos folder<br / >';
$images = dir($albumf.'/slides');
//creating photos.xml code
$pagecode[]= '<?xml version="1.0"?>
<gallery>
';
//looping through photos
while (($file = $images->read()) !== false)
{
//name image file
$imgpath=$albumf.'/slides/'.$file;
//name thumbnail file
$thumbpath=$albumf.'/thumbs/'.$file;
//avoid .htaccess, subfolders etc
if (($file[0] !== '.') && (is_file($imgpath))) {
list($width, $height) = getimagesize($imgpath);
//calculate thumb size
$thumbw= round($width/$height*$thumbh);
//Resize the image
$newthumb = resizeImage($imgpath,$thumbw,$thumbh);
echo 'thumbnail resized for '.$file.' ';
imagejpeg($newthumb,$thumbpath,100);
echo 'thumbnail file created ';
chmod ($thumbpath, 0777);
echo 'thumbnail file permissions left open ';
//image code for photos.xml:
$pagecode[]= '<image img="slides/'. $file . '" thmb="thumbs/'. $file . '" downloadimg="slides/'. $file . '" type="'.substr(strrchr($file, '.'), 1).'" dt="2010.05.29" thumbw="'.$thumbw.'" thumbh="'.$thumbh.'" tags="" category="" printwidth="'.$width.'" printheight="'.$height.'" slidewidth="'.$width.'" slideheight="'.$height.'"><description><![CDATA[]]></description></image>
';
echo ' and the xml code created ';
imagedestroy($newthumb);
echo 'image resource destroyed<br / >';
//unset($thumbw,$width,$height,$imgpath,$thumbpath);
}}
echo 'looped through photos creating thumbs and xml code<br / >';
$images->close();
$pagecode[]= '</gallery>';
//
echo 'made the photos.xml file<br / >';
$photosxml=$albumf.'/photos.xml';
$fh = fopen($photosxml, 'w') or die("can't open file");
foreach ($pagecode as $value) {
fwrite($fh, $value);
}
fclose($fh);
chmod ($photosxml, 0777);
//echo '<b>photos.xml file created</b>';
//
echo 'created symlinks<br />';
$galleryrootdir=getcwd().'/../galleries/galleryroot';
symlink ($galleryrootdir.'/res',$albumf.'/res');
symlink ($galleryrootdir.'/folders.xml',$albumf.'/folders.xml');
symlink ($galleryrootdir.'/index.php',$albumf.'/index.php');
chmod ($photosxml, 0777);
echo 'finished.';
//end code for generating files
}
It just stops after an entire loop, processing an entire image (the 106th image) ie after
echo 'image resource destroyed<br / >';
I've also tried it without the imagedestroy command, and for some reason this goes as far as 107 images on the same folder.
Any ideas? I got some help on here creating some of the code in the first place, so hopefully there's still some people around who are better at this than me!