src/Service/Cdn.php
public static function formatBytes($iBytes, $iPrecision = 2)
    {
        $units  = ['B', 'KB', 'MB', 'GB', 'TB'];
        $iBytes = max($iBytes, 0);
        $pow    = floor(($iBytes ? log($iBytes) : 0) / log(1024));
        $pow    = min($pow, count($units) - 1);

        //  Uncomment one of the following alternatives
        //$iBytes /= pow(1024, $pow);
        $iBytes  /= (1 << (10 * $pow));
        $var     = round($iBytes, $iPrecision) . ' ' . $units[$pow];
        $pattern = '/(.+?)\.(.*?)/';

        return preg_replace_callback(
            $pattern,
            function ($matches) {
                return number_format($matches[1]) . '.' . $matches[2];
            },
            $var
        );
    }
public static function formatBytes($iBytes, $iPrecision = 2)
    {
        $units  = ['B', 'KB', 'MB', 'GB', 'TB'];
        $iBytes = max($iBytes, 0);
        $pow    = floor(($iBytes ? log($iBytes) : 0) / log(1024));
        $pow    = min($pow, count($units) - 1);

        //  Uncomment one of the following alternatives
        //$iBytes /= pow(1024, $pow);
        $iBytes  /= (1 << (10 * $pow));
        $var     = round($iBytes, $iPrecision) . ' ' . $units[$pow];
        $pattern = '/(.+?)\.(.*?)/';

        return preg_replace_callback(
            $pattern,
            function ($matches) {
                return number_format($matches[1]) . '.' . $matches[2];
            },
            $var
        );
    }
public static function formatBytes ( $ iBytes , $ iPrecision = 2 ) { $ units = [ 'B' , 'KB' , 'MB' , 'GB' , 'TB' ] ; $ iBytes = max ( $ iBytes , 0 ) ; $ pow = floor ( ( $ iBytes ? log ( $ iBytes ) : 0 ) / log ( 1024 ) ) ; $ pow = min ( $ pow , count ( $ units ) - 1 ) ; //  Uncomment one of the following alternatives //$iBytes /= pow(1024, $pow); $ iBytes /= ( 1 << ( 10 * $ pow ) ) ; $ var = round ( $ iBytes , $ iPrecision ) . ' ' . $ units [ $ pow ] ; $ pattern = '/(.+?)\.(.*?)/' ; return preg_replace_callback ( $ pattern , function ( $ matches ) { return number_format ( $ matches [ 1 ] ) . '.' . $ matches [ 2 ] ; } , $ var ) ; }
Formats a file size given in bytes into a human-friendly string

@param integer $iBytes     The file size, in bytes
@param integer $iPrecision The precision to use

@return string
Formats a file size given in bytes into a human - friendly string