Handle image upload exception

This commit is contained in:
Hillel Coren 2017-03-20 16:02:59 +02:00
parent 74fd481379
commit ea464aa814
2 changed files with 25 additions and 17 deletions

View File

@ -37,6 +37,7 @@ use Request;
use Response;
use Session;
use stdClass;
use Exception;
use URL;
use Utils;
@ -1053,11 +1054,12 @@ class AccountController extends BaseController
$size = filesize($filePath);
if ($size / 1000 > MAX_DOCUMENT_SIZE) {
Session::flash('warning', 'File too large');
Session::flash('warning', trans('texts.logo_warning_too_large'));
} else {
if ($documentType != 'gif') {
$account->logo = $account->account_key.'.'.$documentType;
try {
$imageSize = getimagesize($filePath);
$account->logo_width = $imageSize[0];
$account->logo_height = $imageSize[1];
@ -1076,6 +1078,9 @@ class AccountController extends BaseController
$disk->getDriver()->putStream($account->logo, $stream, ['mimetype' => $documentTypeData['mime']]);
fclose($stream);
}
} catch (Exception $exception) {
Session::flash('warning', trans('texts.logo_warning_invalid'));
}
} else {
if (extension_loaded('fileinfo')) {
$image = Image::make($path);
@ -1092,7 +1097,7 @@ class AccountController extends BaseController
$account->logo_width = $image->width();
$account->logo_height = $image->height();
} else {
Session::flash('warning', 'Warning: To support gifs the fileinfo PHP extension needs to be enabled.');
Session::flash('warning', trans('texts.logo_warning_fileinfo'));
}
}
}

View File

@ -2422,6 +2422,9 @@ $LANG = array(
'fees_surcharge_help' => 'Customize surcharge :link.',
'label_and_taxes' => 'label and taxes',
'billable' => 'Billable',
'logo_warning_too_large' => 'The image file is too large.',
'logo_warning_fileinfo' => 'Warning: To support gifs the fileinfo PHP extension needs to be enabled.',
'logo_warning_invalid' => 'There was a problem reading the image file, please try a different format.',
);