diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-03-26 19:24:20 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-03-26 19:24:20 +0100 |
commit | 9ce7ecebaf118546bf3a3cbad7ce448d490ade15 (patch) | |
tree | 7187365d3d7eed3670d403e30f22dae2e150b7d4 /app/fn | |
parent | 5019671cf2bba2202c0024f3bd309fe674251226 (diff) | |
download | wcms-9ce7ecebaf118546bf3a3cbad7ce448d490ade15.tar.gz wcms-9ce7ecebaf118546bf3a3cbad7ce448d490ade15.zip |
media add user and permissions data
Diffstat (limited to 'app/fn')
-rw-r--r-- | app/fn/fn.php | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/app/fn/fn.php b/app/fn/fn.php index 60e4722..3ca31c9 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -4,24 +4,29 @@ use Wcms\Medialist; use function Clue\StreamFilter\fun; -function readablesize($bytes) +function readablesize($bytes, $base = 2 ** 10) { $format = ' %d %s'; + if ($base === 2 ** 10) { + $i = 'i'; + } else { + $i = ''; + } + $unit = ''; - if ($bytes < 2 ** 10) { + if ($bytes < $base) { $num = $bytes; - $unit = 'o'; - } elseif ($bytes < 2 ** 20) { - $num = round($bytes / 2 ** 10, 1); - $unit = 'Kio'; - } elseif ($bytes < 2 ** 30) { - $num = round($bytes / 2 ** 20, 1); - $unit = 'Mio'; - } elseif ($bytes < 2 ** 40) { - $num = round($bytes / 2 ** 30, 1); - $unit = 'Gio'; + } elseif ($bytes < $base ** 2) { + $num = round($bytes / $base, 1); + $unit = 'K' . $i; + } elseif ($bytes < $base ** 3) { + $num = round($bytes / $base ** 2, 1); + $unit = 'M' . $i; + } elseif ($bytes < $base ** 4) { + $num = round($bytes / $base ** 3, 1); + $unit = 'G' . $i; } return sprintf($format, $num, $unit); |