helpers/KatoBase.php
public static function formatBytes($bytes, $unit = "", $decimals = 2, $numberOnly = null) {
        $units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4,
            'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);

        $value = 0;
        if ($bytes > 0) {
            // Generate automatic prefix by bytes
            // If wrong prefix given
            if (!array_key_exists($unit, $units)) {
                $pow = floor(log($bytes)/log(1024));
                $unit = array_search($pow, $units);
            }

            // Calculate byte value by prefix
            $value = ($bytes/pow(1024,floor($units[$unit])));
        }

        // If decimals is not numeric or decimals is less than 0
        // then set default value
        if (!is_numeric($decimals) || $decimals < 0) {
            $decimals = 2;
        }

        // Format output
        if (is_null($numberOnly)) {
            return sprintf('%.' . $decimals . 'f '.$unit, $value);
        } else {
            return sprintf('%.' . $decimals . 'f ', $value);
        }
    }
public static function formatBytes($bytes, $unit = "", $decimals = 2, $numberOnly = null) {
        $units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4,
            'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);

        $value = 0;
        if ($bytes > 0) {
            // Generate automatic prefix by bytes
            // If wrong prefix given
            if (!array_key_exists($unit, $units)) {
                $pow = floor(log($bytes)/log(1024));
                $unit = array_search($pow, $units);
            }

            // Calculate byte value by prefix
            $value = ($bytes/pow(1024,floor($units[$unit])));
        }

        // If decimals is not numeric or decimals is less than 0
        // then set default value
        if (!is_numeric($decimals) || $decimals < 0) {
            $decimals = 2;
        }

        // Format output
        if (is_null($numberOnly)) {
            return sprintf('%.' . $decimals . 'f '.$unit, $value);
        } else {
            return sprintf('%.' . $decimals . 'f ', $value);
        }
    }
PHP byteFormat function for formatting bytes
Function takes three parameter: (bytes mandatory, unit optional, decimals optional)

@param $bytes
@param string $unit
@param int $decimals
@param null $numberOnly
@return string