From fcf9611a79c536530d25002136e23d669284cb26 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Tue, 14 Aug 2018 23:59:58 -0600 Subject: [PATCH] Update switch.php --- resources/switch.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/resources/switch.php b/resources/switch.php index 0ede057e4b..bb538d6b5f 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -93,13 +93,15 @@ function event_socket_request_cmd($cmd) { return $response; } -function byte_convert($bytes, $decimals = 2) { - if ($bytes <= 0) { return '0 Bytes'; } - $units = array('B', 'KB', 'MB', 'GB', 'TB'); - $bytes = max($bytes, 0); - $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); - $pow = min($pow, count($units) - 1); - return round($bytes, $precision) . ' ' . $units[$pow]; +function byte_convert($bytes, $precision = 2) { + static $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); + $step = 1024; + $i = 0; + while (($bytes / $step) > 0.9) { + $bytes = $bytes / $step; + $i++; + } + return round($bytes, $precision).' '.$units[$i]; } function remove_config_from_cache($name) {