Jump to content

Trap for errors with getimagesize


RIRedinPA

Recommended Posts

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 protected]", "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?

Link to comment
https://forums.phpfreaks.com/topic/81013-trap-for-errors-with-getimagesize/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.