mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Handle image upload exception
This commit is contained in:
parent
74fd481379
commit
ea464aa814
@ -37,6 +37,7 @@ use Request;
|
|||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
use Exception;
|
||||||
use URL;
|
use URL;
|
||||||
use Utils;
|
use Utils;
|
||||||
|
|
||||||
@ -1053,28 +1054,32 @@ class AccountController extends BaseController
|
|||||||
$size = filesize($filePath);
|
$size = filesize($filePath);
|
||||||
|
|
||||||
if ($size / 1000 > MAX_DOCUMENT_SIZE) {
|
if ($size / 1000 > MAX_DOCUMENT_SIZE) {
|
||||||
Session::flash('warning', 'File too large');
|
Session::flash('warning', trans('texts.logo_warning_too_large'));
|
||||||
} else {
|
} else {
|
||||||
if ($documentType != 'gif') {
|
if ($documentType != 'gif') {
|
||||||
$account->logo = $account->account_key.'.'.$documentType;
|
$account->logo = $account->account_key.'.'.$documentType;
|
||||||
|
|
||||||
$imageSize = getimagesize($filePath);
|
try {
|
||||||
$account->logo_width = $imageSize[0];
|
$imageSize = getimagesize($filePath);
|
||||||
$account->logo_height = $imageSize[1];
|
$account->logo_width = $imageSize[0];
|
||||||
$account->logo_size = $size;
|
$account->logo_height = $imageSize[1];
|
||||||
|
$account->logo_size = $size;
|
||||||
|
|
||||||
// make sure image isn't interlaced
|
// make sure image isn't interlaced
|
||||||
if (extension_loaded('fileinfo')) {
|
if (extension_loaded('fileinfo')) {
|
||||||
$image = Image::make($path);
|
$image = Image::make($path);
|
||||||
$image->interlace(false);
|
$image->interlace(false);
|
||||||
$imageStr = (string) $image->encode($documentType);
|
$imageStr = (string) $image->encode($documentType);
|
||||||
$disk->put($account->logo, $imageStr);
|
$disk->put($account->logo, $imageStr);
|
||||||
|
|
||||||
$account->logo_size = strlen($imageStr);
|
$account->logo_size = strlen($imageStr);
|
||||||
} else {
|
} else {
|
||||||
$stream = fopen($filePath, 'r');
|
$stream = fopen($filePath, 'r');
|
||||||
$disk->getDriver()->putStream($account->logo, $stream, ['mimetype' => $documentTypeData['mime']]);
|
$disk->getDriver()->putStream($account->logo, $stream, ['mimetype' => $documentTypeData['mime']]);
|
||||||
fclose($stream);
|
fclose($stream);
|
||||||
|
}
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
Session::flash('warning', trans('texts.logo_warning_invalid'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (extension_loaded('fileinfo')) {
|
if (extension_loaded('fileinfo')) {
|
||||||
@ -1092,7 +1097,7 @@ class AccountController extends BaseController
|
|||||||
$account->logo_width = $image->width();
|
$account->logo_width = $image->width();
|
||||||
$account->logo_height = $image->height();
|
$account->logo_height = $image->height();
|
||||||
} else {
|
} else {
|
||||||
Session::flash('warning', 'Warning: To support gifs the fileinfo PHP extension needs to be enabled.');
|
Session::flash('warning', trans('texts.logo_warning_fileinfo'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2422,6 +2422,9 @@ $LANG = array(
|
|||||||
'fees_surcharge_help' => 'Customize surcharge :link.',
|
'fees_surcharge_help' => 'Customize surcharge :link.',
|
||||||
'label_and_taxes' => 'label and taxes',
|
'label_and_taxes' => 'label and taxes',
|
||||||
'billable' => 'Billable',
|
'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.',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user