Uploaded file sizes seem to be reported differently by PHP filesize(); changing divis...
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 23 May 2020 19:29:27 +0000 (19:29 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 23 May 2020 19:29:27 +0000 (19:29 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14861 7612ce4b-ef26-0410-bec9-ea0150e637f0

config/config_local.example.php
functions/strings.php
functions/template/general_util.php
src/compose.php
templates/default/compose_attachments.tpl

index 1473f0a61dfa2cfb383071f4d82a34fe83efb629..1cac112971573979cb7646d4680405912765e6d0 100644 (file)
  * traffic from a proxy so the normal $PHP_SELF does not resolve
  * to what it should be for the real client.
  *
  * 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;
+ *
  */
  */
index 9e295df6dfe18fb299a7aa5e93105491596cb626..515e87e8c19b6ccb660468ff7e0d3dc404846942 100644 (file)
@@ -654,18 +654,19 @@ function OneTimePadCreate ($length=100) {
   * a more easily digested (readable) format
   *
   * @param int $bytes the size in bytes
   * 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
   *
   */
   *
   * @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");
 
     $type = _("KiB");
 
-    if ($bytes / 1024 > 1) {
-        $bytes /= 1024;
+    if ($bytes / $filesize_divisor > 1) {
+        $bytes /= $filesize_divisor;
         $type = _("MiB");
     }
 
         $type = _("MiB");
     }
 
index 08d41d62a735a5cef0676f93347cccb39b592415..09a502ffdacc738ece62727ee76951de0b67b96b 100644 (file)
@@ -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
 //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
  **/
  * @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);
 }
 }
index afc20be3ef486d353e985dbf0fc92ef6bbe4aa32..71f3ebcca6755e325c12150a79032aaae856c7fb 100644 (file)
@@ -1484,7 +1484,9 @@ function showInputForm ($session, $values=false) {
         }
 
         $attach = array();
         }
 
         $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) {
         $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);
         $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...
         //
 
         // access keys...
         //
index 83416672533d865c76280fcdbed999c1d653d165..75f76bfd95bc0f322755a4425b431996ff3bcd12 100644 (file)
@@ -55,7 +55,7 @@ extract($t);
    <input type="checkbox" name="delete[]" id="delete<?php echo $attachment_count; ?>" accesskey="<?php echo ($attachment_count % 10); ?>" value="<?php echo $attach['Key']; ?>" />
   </td>
   <td class="fieldValue"><label for="delete<?php echo $attachment_count; ?>">
    <input type="checkbox" name="delete[]" id="delete<?php echo $attachment_count; ?>" accesskey="<?php echo ($attachment_count % 10); ?>" value="<?php echo $attach['Key']; ?>" />
   </td>
   <td class="fieldValue"><label for="delete<?php echo $attachment_count; ?>">
-   <?php echo $attach['FileName']; ?> - <?php echo $attach['ContentType']; ?> (<?php echo humanReadableSize($attach['Size']); ?>)
+   <?php echo $attach['FileName']; ?> - <?php echo $attach['ContentType']; ?> (<?php echo humanReadableSize($attach['Size'], $upload_filesize_divisor); ?>)
   </label></td>
  </tr>
         <?php
   </label></td>
  </tr>
         <?php