From: pdontthink Date: Sat, 23 May 2020 19:29:27 +0000 (+0000) Subject: Uploaded file sizes seem to be reported differently by PHP filesize(); changing divis... X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=3ab5b55bba23336f2813fc1bbac7ae1360fb33ab Uploaded file sizes seem to be reported differently by PHP filesize(); changing divisor from 1024 to 1000 in this case. You can set $upload_filesize_divisor in config/config_local.php to 1024 if this breaks things for you. Feedback appreciated for this one. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14861 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/config/config_local.example.php b/config/config_local.example.php index 1473f0a6..1cac1129 100644 --- a/config/config_local.example.php +++ b/config/config_local.example.php @@ -193,4 +193,11 @@ * traffic from a proxy so the normal $PHP_SELF does not resolve * to what it should be for the real client. * + * $upload_filesize_divisor allows the administrator to specify + * the divisor used when converting the size of an uploaded file + * as given by PHP's filesize() and converted to human-digestable + * form. By default, 1000 is used, but 1024 may be necessary in + * some environments. + * $upload_filesize_divisor = 1024; + * */ diff --git a/functions/strings.php b/functions/strings.php index 9e295df6..515e87e8 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -654,18 +654,19 @@ function OneTimePadCreate ($length=100) { * a more easily digested (readable) format * * @param int $bytes the size in bytes + * @param int $filesize_divisor the divisor we'll use (OPTIONAL; default 1024) * * @return string The size in human readable format * * @since 1.0 * */ -function show_readable_size($bytes) { - $bytes /= 1024; +function show_readable_size($bytes, $filesize_divisor) { + $bytes /= $filesize_divisor; $type = _("KiB"); - if ($bytes / 1024 > 1) { - $bytes /= 1024; + if ($bytes / $filesize_divisor > 1) { + $bytes /= $filesize_divisor; $type = _("MiB"); } diff --git a/functions/template/general_util.php b/functions/template/general_util.php index 08d41d62..09a502ff 100644 --- a/functions/template/general_util.php +++ b/functions/template/general_util.php @@ -169,9 +169,10 @@ function displayErrors () { //FIXME: I think this is needless since there is no reason templates cannot just call directly to show_readable_size * * @param int size to be converted to human-readable + * @param int filesize_divisor the divisor we'll use (OPTIONAL; default 1024) * @return string human-readable form * @since 1.5.2 **/ -function humanReadableSize ($size) { - return show_readable_size($size); +function humanReadableSize ($size, $filesize_divisor=1024) { + return show_readable_size($size, $filesize_divisor); } diff --git a/src/compose.php b/src/compose.php index afc20be3..71f3ebcc 100644 --- a/src/compose.php +++ b/src/compose.php @@ -1484,7 +1484,9 @@ function showInputForm ($session, $values=false) { } $attach = array(); - global $username, $attachment_dir; + global $username, $attachment_dir, $upload_filesize_divisor; + if (empty($upload_filesize_divisor)) + $upload_filesize_divisor = 1000; // *not* 1024 -- does this break for some users? $hashed_attachment_dir = getHashedDir($username, $attachment_dir); if (!empty($attach_array)) { foreach ($attach_array as $key => $attachment) { @@ -1507,6 +1509,7 @@ function showInputForm ($session, $values=false) { $max = min($sizes); $oTemplate->assign('max_file_size', empty($max) ? -1 : $max); $oTemplate->assign('attachments', $attach); + $oTemplate->assign('upload_filesize_divisor', $upload_filesize_divisor); // access keys... // diff --git a/templates/default/compose_attachments.tpl b/templates/default/compose_attachments.tpl index 83416672..75f76bfd 100644 --- a/templates/default/compose_attachments.tpl +++ b/templates/default/compose_attachments.tpl @@ -55,7 +55,7 @@ extract($t);