RIRedinPA Posted December 10, 2007 Share Posted December 10, 2007 I'm building a site that allows intranet users to search our photo archives. When I try to getimagesize of some files, if they are missing PHP displays a warning error. Warning: getimagesize(/Volumes/6134/jpeg/6134-1.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /Library/WebServer/Dev/area51/scriptarama/results.php on line 57 I want to suppress just this error (not all warnings) because I know, through mismanagement, not all of our records in the db will have an associated thumbnail. I wrote this function but it doesn't catch all of them: function getFileSize($logNum, $fileCount) { $fileSizeArray = array(); for ($i=1; $i<=$fileCount; $i++) { $path = "/Volumes/" . $logNum . "/jpeg/" . $logNum . "-" . $i . ".jpg"; if (file_exists($path)) { $fileSizeArray [] = list($width, $height, $type, $attr) = getimagesize("/Volumes/ARTARCHIVE/MerionPhotoArchive/" . $logNum . "/jpeg/" . $logNum . "-" . $i . ".jpg"); } else { //generate custom error message $errorMessage = "On: " . date ("d-M-Y h:i:s", mktime()) . " a search was conducted of the Photo Archive with these parameters:\n\n" ; for ($z=0; $z<=count($HTTP_POST_VARS); $z++) { $errorMessage .= $HTTP_POST_VARS[$z] . "\n"; } $errorMessage .= "\n\nThe page couid not return a file size for " . $logNum . "-" . $i . ".jpg. No such file."; //email message to me mail("email@email.com", "Photo Archive Error", $errorMessage); $errorNumbers = array(120, 150, 0, 0, "true"); $fileSizeArray [] = $errorNumbers; } } return $fileSizeArray; } I think what is happening is my function is bypassing those files which don't exists but there are others which are failing the getimagesize function for other reasons. (file is corrupted in some way, resource fork issues, something like that) Is there a way I can trap for those? Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 getimagesize() like most php functions, returns false on error. test for that. ps: [ code ][/ code] tags (without the spaces) would make your code much easier to read on the forum. 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.