Ver Fonte

Uploaded file sizes seem to be reported differently by PHP filesize(); changing divisor from 1024 to 1000 in this case. You can set in config/config_local.php to 1024 if this breaks things for you. Feedback appreciated for this one.

pdontthink há 5 anos atrás
pai
commit
1dd515365c

+ 7 - 0
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;
+ *
  */

+ 5 - 4
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");
     }
 

+ 3 - 2
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);
 }

+ 4 - 1
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...
         //

+ 1 - 1
templates/default/compose_attachments.tpl

@@ -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; ?>">
-   <?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