From 119a5ca8d8dca528a90914414d55d238243fa6fa Mon Sep 17 00:00:00 2001 From: Marek Bachmann Date: Wed, 30 Nov 2022 21:27:14 +0100 Subject: [PATCH 1/2] Adjusted code use of shorthandnotation for image size upload limits --- js_upload/js_upload.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/js_upload/js_upload.php b/js_upload/js_upload.php index 8d8af072..0c8e5836 100644 --- a/js_upload/js_upload.php +++ b/js_upload/js_upload.php @@ -39,7 +39,7 @@ function js_upload_form(App $a, array &$b) '$cancel' => DI::l10n()->t('Cancel'), '$failed' => DI::l10n()->t('Failed'), '$post_url' => $b['post_url'], - '$maximagesize' => intval(DI::config()->get('system', 'maximagesize')), + '$maximagesize' => Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')), ]); } @@ -51,7 +51,7 @@ function js_upload_post_init(App $a, array &$b) $allowedExtensions = ['jpeg', 'gif', 'png', 'jpg']; // max file size in bytes - $sizeLimit = DI::config()->get('system', 'maximagesize'); + $sizeLimit = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')); $uploader = new qqFileUploader($allowedExtensions, $sizeLimit); @@ -200,21 +200,6 @@ class qqFileUploader } - private function toBytes($str) - { - $val = trim($str); - $last = strtolower($str[strlen($str) - 1]); - switch ($last) { - case 'g': - $val *= 1024; - case 'm': - $val *= 1024; - case 'k': - $val *= 1024; - } - return $val; - } - /** * Returns array('success'=>true) or array('error'=>'error message') */ From efb98c845795a9c0fc746670de76901889c90598 Mon Sep 17 00:00:00 2001 From: Marek Bachmann Date: Wed, 30 Nov 2022 21:33:11 +0100 Subject: [PATCH 2/2] Wrapped Strings::getBytesFromShorthand() around the last overseen DI::config()->get('system', 'maximagesize') --- js_upload/js_upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js_upload/js_upload.php b/js_upload/js_upload.php index 0c8e5836..e93ce7d6 100644 --- a/js_upload/js_upload.php +++ b/js_upload/js_upload.php @@ -221,7 +221,7 @@ class qqFileUploader // } - $maximagesize = DI::config()->get('system', 'maximagesize'); + $maximagesize = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')); if (($maximagesize) && ($size > $maximagesize)) { return ['error' => DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize))];