farkewie Posted November 10, 2007 Share Posted November 10, 2007 Hi i have created a thumbnail script seems to be working but it still leaves errors. i know its working because i have 30 images in my test folder and i get 30 thumbs. code: <?php $dir = "images"; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } sort($files); rsort($files); $dir = "images/"; if (!file_exists($dir."/thumbs")){ mkdir($dir."/thumbs"); } if (!file_exists($dir."/thumbs".$files)){ foreach ($files as $files) { $minwidth = "150"; $minheight = "150"; $photosize = getimagesize($dir.$files); // Get image size and scale ratio $scale = min("150"/$photosize[0], "150"/$photosize[1]); if ($scale < 1) { $width = floor($scale*$photosize[0]); $height = floor($scale*$photosize[1]); } else { $width = $minwidth; $height = $minheight; } if ($photosize['mime']=="image/jpeg") { $resizedimage = imagecreatetruecolor($width, $height); $thumbimage = imagecreatefromjpeg($dir.$files); imagecopyresampled($resizedimage, $thumbimage, 0, 0, 0, 0, $width, $height, $photosize[0], $photosize[1]); imagejpeg($resizedimage,$dir."/thumbs/THUMBS_".$files,100); imageDestroy($resizedimage); imageDestroy($thumbimage); } } } ?> Error: Warning: getimagesize(images/thumbs) [function.getimagesize]: failed to open stream: Permission denied in Z:\www\htdocs\personal\test.php on line 28 Warning: Division by zero in Z:\www\htdocs\personal\test.php on line 30 Warning: Division by zero in Z:\www\htdocs\personal\test.php on line 30 Warning: getimagesize(images/..) [function.getimagesize]: failed to open stream: Permission denied in Z:\www\htdocs\personal\test.php on line 28 Warning: Division by zero in Z:\www\htdocs\personal\test.php on line 30 Warning: Division by zero in Z:\www\htdocs\personal\test.php on line 30 Warning: getimagesize(images/.) [function.getimagesize]: failed to open stream: Permission denied in Z:\www\htdocs\personal\test.php on line 28 Warning: Division by zero in Z:\www\htdocs\personal\test.php on line 30 Warning: Division by zero in Z:\www\htdocs\personal\test.php on line 30 Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 try this modified code <?php $dir = "images"; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } sort($files); rsort($files); $dir = "images/"; if (!file_exists($dir."/thumbs")){ mkdir($dir."/thumbs"); } foreach ($files as $file) { if (!file_exists($dir."/THUMBS_".$file)){ $minwidth = "150"; $minheight = "150"; $photosize = getimagesize($dir.$file); // Get image size and scale ratio $scale = min("150"/$photosize[0], "150"/$photosize[1]); if ($scale < 1) { $width = floor($scale*$photosize[0]); $height = floor($scale*$photosize[1]); } else { $width = $minwidth; $height = $minheight; } if ($photosize['mime']=="image/jpeg") { $resizedimage = imagecreatetruecolor($width, $height); $thumbimage = imagecreatefromjpeg($dir.$file); imagecopyresampled($resizedimage, $thumbimage, 0, 0, 0, 0, $width, $height, $photosize[0], $photosize[1]); imagejpeg($resizedimage,$dir."/thumbs/THUMBS_".$file,100); imageDestroy($resizedimage); imageDestroy($thumbimage); } } } ?> Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 10, 2007 Author Share Posted November 10, 2007 Sorry it the exact same images. im ging to try a different set of images incase some are corrupt. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 10, 2007 Author Share Posted November 10, 2007 Still the same but i used 40 images this time as apposed to 31 and i only got 6 lines of errors this time instead of 9 Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 if (!file_exists($dir."/THUMBS_".$file)){ should be if (!file_exists($dir."thumbs/THUMBS_".$file)){ Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 10, 2007 Author Share Posted November 10, 2007 Still the same. I also tried taking all the spaces out of the image names.. i dont think it should make a difference but my testing server is on a winxp box?? Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 10, 2007 Author Share Posted November 10, 2007 I have tried running it on my hosted server to see if that made a difference its still the same.. any ideas? Quote Link to comment Share on other sites More sharing options...
marcus Posted November 10, 2007 Share Posted November 10, 2007 Here's an idea. CHMOD all the folders to 777, will make them both readable AND writable, which is what you need. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 10, 2007 Author Share Posted November 10, 2007 oops i clicked solved...:-) Its not.. im still getting the same errors... i made the directory images 777 and all the images in it 777? Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 10, 2007 Author Share Posted November 10, 2007 Ok so i found what the problem is i just dont know how to fix it Code: <?php print_r($files); ?> Returns. Array ( [0] => thumbs [1] => image021.jpg [2] => image020.jpg [3] => image019.jpg [4] => image018.jpg [5] => image017.jpg [6] => image016.jpg [7] => image015.jpg [8] => image014.jpg [9] => image013.jpg [10] => image012.jpg [11] => image011.jpg [12] => image010.jpg [13] => image009.jpg [14] => image008.jpg [15] => image007.jpg [16] => image006.jpg [17] => image005.jpg [18] => image004.jpg [19] => image003.jpg [20] => image002.jpg [21] => image001.jpg [22] => .. [23] => . ) notice the dots don the bottom? how do i exlude them from my thumbnail creation? Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 10, 2007 Share Posted November 10, 2007 Putting this in your while loop will skip the dots: if($filename == '.' || $filename == '..'){continue;} Like this i guess: while (false !== ($filename = readdir($dh))) { if($filename == '.' || $filename == '..'){continue;} $files[] = $filename; } EDIT: I had the variable names wrong at first, just fixed them. Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 10, 2007 Author Share Posted November 10, 2007 Perfect. thank you all for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.