Fix wrong comparison in installation pre-checks

The upload_max_filesize and post_max_size values from php.ini can use
K, M, or G suffixes (e.g. 2048K, 8M). The previous code cast these
values directly to int and then multiplied by 1024*1024, ignoring the
unit suffix entirely. This caused incorrect comparisons like 2048K
being treated as greater than 8M.

Add a convertToBytes() helper that properly parses the PHP shorthand
notation into bytes before comparing.

Fixes #3085
This commit is contained in:
cemacar
2026-03-16 18:16:24 +03:00
parent 26ed5a95c2
commit e1c317c697

View File

@@ -10,6 +10,18 @@ DJ7NT - Docker Readiness - April 2024
HB9HIL - Big UX and backend upgrade - July 2024
*/
require_once('includes/install_config/install_lib.php');
function convertToBytes(string $value): int {
$value = trim($value);
$num = (int) $value;
$unit = strtoupper(substr($value, -1));
switch ($unit) {
case 'G': return $num * 1024 * 1024 * 1024;
case 'M': return $num * 1024 * 1024;
case 'K': return $num * 1024;
default: return $num;
}
}
$http_scheme = is_https() ? "https" : "http";
$directory = ltrim(str_replace('/install', '', dirname($_SERVER['SCRIPT_NAME'])), '/');
@@ -171,7 +183,7 @@ if (!file_exists('.lock') && !file_exists('../application/config/config.php') &&
<td>
<?php
$maxUploadFileSize = ini_get('upload_max_filesize');
$maxUploadFileSizeBytes = (int)($maxUploadFileSize) * (1024 * 1024); // convert to bytes
$maxUploadFileSizeBytes = convertToBytes($maxUploadFileSize);
if ($maxUploadFileSizeBytes >= ($upload_max_filesize * 1024 * 1024)) { // compare with given value in bytes
?>
<span class="badge text-bg-success"><?php echo $maxUploadFileSize; ?></span>
@@ -190,7 +202,7 @@ if (!file_exists('.lock') && !file_exists('../application/config/config.php') &&
<td>
<?php
$maxUploadFileSize = ini_get('post_max_size');
$maxUploadFileSizeBytes = (int)($maxUploadFileSize) * (1024 * 1024); // convert to bytes
$maxUploadFileSizeBytes = convertToBytes($maxUploadFileSize);
if ($maxUploadFileSizeBytes >= ($post_max_size * 1024 * 1024)) { // compare with given value in bytes
?>
<span class="badge text-bg-success"><?php echo $maxUploadFileSize; ?></span>