From 5f2a948f5551f0c168e6572ba500724bddf4c576 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 21 Apr 2018 18:06:42 +0200 Subject: V2 W V0 M --- fn/fn.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'fn/fn.php') diff --git a/fn/fn.php b/fn/fn.php index b075d57..65d14f4 100644 --- a/fn/fn.php +++ b/fn/fn.php @@ -52,5 +52,30 @@ function search($haystack, $debut, $fin) } +function readablesize(int $bytes) +{ + + $num = 5; + $location = 'tree'; + $format = ' %d %s'; + + + + if ($bytes < 2 ** 10) { + $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'; + } + + return sprintf($format, $num, $unit); +} ?> -- cgit v1.2.3