From 9e2f37477b41035778633d6a10c5ad349bd2acdd Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 19 May 2014 19:27:22 +0200 Subject: [PATCH] Added support to 404 URLs in thumbnail generator --- src/Helpers/TransferHelper.php | 9 ++++++++- .../SmartThumbnailGenerator.php | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Helpers/TransferHelper.php b/src/Helpers/TransferHelper.php index 83b0829a..cd6353e0 100644 --- a/src/Helpers/TransferHelper.php +++ b/src/Helpers/TransferHelper.php @@ -13,7 +13,14 @@ class TransferHelper } set_time_limit(0); - $srcHandle = fopen($srcUrl, 'rb'); + try + { + $srcHandle = fopen($srcUrl, 'rb'); + } + catch (Exception $e) + { + throw new SimpleException('Cannot open URL for reading: ' . $e->getMessage()); + } if (!$srcHandle) throw new SimpleException('Cannot open URL for reading'); diff --git a/src/ThumbnailGenerators/SmartThumbnailGenerator.php b/src/ThumbnailGenerators/SmartThumbnailGenerator.php index a884ecc5..47d83b81 100644 --- a/src/ThumbnailGenerators/SmartThumbnailGenerator.php +++ b/src/ThumbnailGenerators/SmartThumbnailGenerator.php @@ -5,10 +5,18 @@ class SmartThumbnailGenerator implements IThumbnailGenerator { $tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.jpg'; - TransferHelper::download( - $url, - $tmpPath, - null); + try + { + TransferHelper::download( + $url, + $tmpPath, + null); + } + catch (SimpleException $e) + { + echo $e->getMessage(); + return false; + } $ret = self::generateFromFile($tmpPath, $dstPath, $width, $height);