Page 1 of 1

PHP: cannot catch errors.

Posted: 2014-12-23T09:27:00-07:00
by sparkdaemon
First, I'm French, i will try to speak English best as i can.

I'm running a server on Debian (Debian GNU/Linux 7) with php (5.4.35-0+deb7u2) and Apache.

I'm creating an API with Laravel, and i have a problem when i upload a file that Imagick can't use.

Code: Select all

static function createThumbWithHash($filePath, $fileHash) {
                try
                {
                     $im = new \imagick();
                     $im->setResourceLimit(\imagick::RESOURCETYPE_MEMORY, 1024);
                     $im->setResourceLimit(\imagick::RESOURCETYPE_MAP, 256);
                     $im->setResourceLimit(\imagick::RESOURCETYPE_AREA, 1512);
                     $im->setResourceLimit(\imagick::RESOURCETYPE_FILE, 768);
                     $im->setResourceLimit(\imagick::RESOURCETYPE_DISK, -1);
                 
                     $tmpFile = tempnam(sys_get_temp_dir(), "thumb_");
                     $im->readImage($filePath);
                     $im->setImageFormat('jpg');
                     //Scale the image
                     $im->thumbnailImage(200, 200, true);
                     //Write the new image to a file
                     $im->writeImage($tmpFile);

                 } catch (ErrorDelegate $e) {

                         Log::info("getThumbHash: ".$e->getMessage());
                         return Response::json(array("error" => "Not image", "id" => "4", "desc" => "not image"), 418);
                 }
                 catch (Exception $e){
                         Log::info("getThumbHash: Unknown Error: " . $e->getMessage());
                         return Response::json(array("error" => "Unknown", "id" => "5", "desc" => "Unknown", "ErrorLevel" => "Error"), 418);
                 }
                 if (!self::moveFileToHash($tmpFile, $fileHash, "thumbnail"))
                         return false;
                 return true;
         } 
the exception occurs at:

Code: Select all

$im->readImage($filePath);
When i upload a file that imagick can't use, Imagick throw an exception, but my code don't catch it and the server return code 500, But Laravel catch the error, i don't understand why. (I searched for many solutions on the web)

Can you help me guys?

thanks ♥

Re: PHP: cannot catch errors.

Posted: 2014-12-23T09:37:40-07:00
by Bonzo
Search this page for error and it might help you out: http://www.phpro.org/tutorials/Imagick.html

Re: PHP: cannot catch errors.

Posted: 2014-12-23T09:44:39-07:00
by sparkdaemon
I already seen this page, and it doesn't help me :s

Re: PHP: cannot catch errors.

Posted: 2014-12-29T00:55:13-07:00
by sparkdaemon
Up ^^' I still need help please :)

Re: PHP: cannot catch errors.

Posted: 2014-12-29T03:48:43-07:00
by Bonzo
I would try posting on a forum like sitepoint in the php section as you may find a way to catch the error.

Re: PHP: cannot catch errors.

Posted: 2014-12-30T08:24:01-07:00
by sparkdaemon
sitepoint? i don't know this site, i go see, thanks