summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-01-28 13:48:03 +0100
committerSimon Rettberg2019-01-28 13:48:03 +0100
commit54a0a4c9b920bce1dc4e93d2cf05ebbea6502be0 (patch)
tree2463200ecdf40f10f9d40f96d361d7fdc0317d23
parent[statistics] Minor refactoring (PHP >= 5.6) (diff)
downloadslx-admin-54a0a4c9b920bce1dc4e93d2cf05ebbea6502be0.tar.gz
slx-admin-54a0a4c9b920bce1dc4e93d2cf05ebbea6502be0.tar.xz
slx-admin-54a0a4c9b920bce1dc4e93d2cf05ebbea6502be0.zip
[inc/Util] readableFileSize: support input in KB/MB/...
-rw-r--r--inc/util.inc.php5
1 files changed, 3 insertions, 2 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 1a5cbefe..e459cc46 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -234,9 +234,10 @@ SADFACE;
*
* @param float|int $bytes numeric value of the filesize to make readable
* @param int $decimals number of decimals to show, -1 for automatic
+ * @param int $shift how many units to skip, i.e. if you pass in KiB or MiB
* @return string human readable string representing the given file size
*/
- public static function readableFileSize($bytes, $decimals = -1)
+ public static function readableFileSize($bytes, $decimals = -1, $shift = 0)
{
$bytes = round($bytes);
static $sz = array('Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
@@ -249,7 +250,7 @@ SADFACE;
$decimals = 2 - floor(strlen((int)$bytes) - 1);
}
}
- return sprintf("%.{$decimals}f", $bytes) . "\xe2\x80\x89" . $sz[$factor];
+ return sprintf("%.{$decimals}f", $bytes) . "\xe2\x80\x89" . $sz[$factor + $shift];
}
public static function sanitizeFilename($name)