* 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;
+ *
*/
* 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");
}
//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);
}
}
$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) {
$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...
//
<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