From 54a0a4c9b920bce1dc4e93d2cf05ebbea6502be0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 28 Jan 2019 13:48:03 +0100 Subject: [inc/Util] readableFileSize: support input in KB/MB/... --- inc/util.inc.php | 5 +++-- 1 file 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) -- cgit v1.2.3-55-g7522