From 247c9673ef312d877ea503d73fba0a71395b5b62 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Sun, 22 Dec 2024 18:57:58 +0300 Subject: [PATCH] Update FileUploader.php --- webfiori/file/FileUploader.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/webfiori/file/FileUploader.php b/webfiori/file/FileUploader.php index 0b69066..cccf873 100644 --- a/webfiori/file/FileUploader.php +++ b/webfiori/file/FileUploader.php @@ -607,6 +607,27 @@ private function getFileArr($fileOrFiles,$replaceIfExist, ?string $idx): array { return $fileInfoArr; } + /** + * Returns the value of the directive 'upload_max_filesize' in KB. + * + * @return int + */ + public static function getMaxFileSize() : int { + $val = ini_get('upload_max_filesize'); + $lastChar = strtoupper($val[strlen($val) - 1]); + + switch ($lastChar) { + case 'M' : { + return intval($val) * 1000; + } case 'K' : { + return intval($val); + } case 'G' : { + return intval($val) * 1000000; + } default : { + return intval($val) / 1000; + } + } + } /** * Checks if PHP upload code is error or not. * @@ -625,7 +646,7 @@ private function isError(int $code): bool { return false; } case UPLOAD_ERR_INI_SIZE:{ - $this->uploadStatusMessage = 'File Size is Larger Than '.(intval(ini_get('upload_max_filesize')) / 1000).'KB. Found in php.ini.'; + $this->uploadStatusMessage = 'File Size is Larger Than '.(self::getMaxFileSize()).'KB. Found in php.ini.'; break; } case UPLOAD_ERR_PARTIAL:{