Hi All, I have a script that takes a directory of user uploaded files and resizes them to the required sizes. I was given ~750 test pix to run through, and my solution only sorta works. The problem is that it won't get through the whole batch without dying. It will process anywhere between 13 to 350 pix in one go before stoping, and it takes 3 or 4 tries to get it restarted.
I have set_time_limit(0); in the code, so it isn't timing out. I can't even think what else it could be, so any help is greatly appreciated. thanks in advance, Craig if ($HTTP_GET_VARS['resize'] == 'resize') { $fixedCount = 0; foreach ($picList as $pic) { $picPath = '../uploads/jpegPics/' . $pic; $smallDest = '../images/products/thumbs/' . $pic; $midDest = '../images/products/normal/' . $pic; $bigDest = '../images/products/big/' . $pic; if (filesize($picPath) > 2000000) { unlink($picPath); echo "==>PROBLEM: $pic is more than 2 Mb and has not been resized<BR>"; } else { $big = resizeImageJPG(450, 450, $picPath, $bigDest, 1); $mid = resizeImageJPG(204, 204, $picPath, $midDest, 1); $thumb = resizeImageJPG(70, 70, $picPath, $smallDest, 1); if ($thumb && $mid && $big) { echo "$pic has been resized<BR>"; $fixedCount++; unlink($picPath); flush(); } else { if ($pic=='noPix'||$pic=='thumbs'||$pic=='normal'||$pic=='big') { //won't show error when directories aren't resized } else { echo "==>PROBLEM: resize of $pic failed.<BR>"; } } } } echo "$fixedCount files have been successfully resized<br>"; } function resizeImageJPG($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgqual) { $g_imgcomp=100-$imgqual; $g_srcfile=$sourcefile; $g_dstfile=$destfile; $g_fw=$forcedwidth; $g_fh=$forcedheight; if(file_exists($g_srcfile)) { $g_is=getimagesize($g_srcfile); if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh)) { $g_iw=$g_fw; $g_ih=($g_fw/$g_is[0])*$g_is[1]; } else { $g_ih=$g_fh; $g_iw=($g_ih/$g_is[1])*$g_is[0]; } $img_src=imagecreatefromjpeg($g_srcfile); $img_dst=imagecreatetruecolor($g_iw,$g_ih); $imgCpRES=imagecopyresampled($img_dst,$img_src,0,0,0,0,$g_iw,$g_ih,$g_is[0], $g_is[1]); $imgJPEG=imagejpeg($img_dst, $g_dstfile, $g_imgcomp); imagedestroy($img_dst); if ($imgJPEG) { return true; } else{ return false; } } }// end function resizeImageJPG -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php