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@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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.