Added support to 404 URLs in thumbnail generator

This commit is contained in:
Marcin Kurczewski 2014-05-19 19:27:22 +02:00
parent dcfe6a00ea
commit 9e2f37477b
2 changed files with 20 additions and 5 deletions

View file

@ -13,7 +13,14 @@ class TransferHelper
} }
set_time_limit(0); set_time_limit(0);
try
{
$srcHandle = fopen($srcUrl, 'rb'); $srcHandle = fopen($srcUrl, 'rb');
}
catch (Exception $e)
{
throw new SimpleException('Cannot open URL for reading: ' . $e->getMessage());
}
if (!$srcHandle) if (!$srcHandle)
throw new SimpleException('Cannot open URL for reading'); throw new SimpleException('Cannot open URL for reading');

View file

@ -5,10 +5,18 @@ class SmartThumbnailGenerator implements IThumbnailGenerator
{ {
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.jpg'; $tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.jpg';
try
{
TransferHelper::download( TransferHelper::download(
$url, $url,
$tmpPath, $tmpPath,
null); null);
}
catch (SimpleException $e)
{
echo $e->getMessage();
return false;
}
$ret = self::generateFromFile($tmpPath, $dstPath, $width, $height); $ret = self::generateFromFile($tmpPath, $dstPath, $width, $height);