public static function bytesToSizeString($bytes, int $decimals = null, string $decimalSeparator = null, string $thousandsSeparator = null): string
    {
        if (!is_int($bytes) && !is_float($bytes)) {
            if (is_numeric($bytes)) {
                $bytes = (float)$bytes;
            } else {
                $bytes = 0;
            }
        }

        // FIXME: The defaults should again be in the function declaration and nulls not allowed. This is a breaking change though.
        if ($decimals === null) {
            $decimals = 0;
        }
        if ($decimalSeparator === null) {
            $decimalSeparator = '.';
        }
        if ($thousandsSeparator === null) {
            $thousandsSeparator = ',';
        }

        $bytes = max($bytes, 0);
        $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
        $pow = min($pow, count(self::$sizeUnits) - 1);
        $bytes /= pow(2, (10 * $pow));

        return sprintf(
            '%s %s',
            number_format(round($bytes, 4 * $decimals), $decimals, $decimalSeparator, $thousandsSeparator),
            self::$sizeUnits[$pow]
        );
    }
public static function bytesToSizeString($bytes, int $decimals = null, string $decimalSeparator = null, string $thousandsSeparator = null): string
    {
        if (!is_int($bytes) && !is_float($bytes)) {
            if (is_numeric($bytes)) {
                $bytes = (float)$bytes;
            } else {
                $bytes = 0;
            }
        }

        // FIXME: The defaults should again be in the function declaration and nulls not allowed. This is a breaking change though.
        if ($decimals === null) {
            $decimals = 0;
        }
        if ($decimalSeparator === null) {
            $decimalSeparator = '.';
        }
        if ($thousandsSeparator === null) {
            $thousandsSeparator = ',';
        }

        $bytes = max($bytes, 0);
        $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
        $pow = min($pow, count(self::$sizeUnits) - 1);
        $bytes /= pow(2, (10 * $pow));

        return sprintf(
            '%s %s',
            number_format(round($bytes, 4 * $decimals), $decimals, $decimalSeparator, $thousandsSeparator),
            self::$sizeUnits[$pow]
        );
    }
public static function bytesToSizeString ( $ bytes , int $ decimals = null , string $ decimalSeparator = null , string $ thousandsSeparator = null ) : string { if ( ! is_int ( $ bytes ) && ! is_float ( $ bytes ) ) { if ( is_numeric ( $ bytes ) ) { $ bytes = ( float ) $ bytes ; } else { $ bytes = 0 ; } } // FIXME: The defaults should again be in the function declaration and nulls not allowed. This is a breaking change though. if ( $ decimals === null ) { $ decimals = 0 ; } if ( $ decimalSeparator === null ) { $ decimalSeparator = '.' ; } if ( $ thousandsSeparator === null ) { $ thousandsSeparator = ',' ; } $ bytes = max ( $ bytes , 0 ) ; $ pow = floor ( ( $ bytes ? log ( $ bytes ) : 0 ) / log ( 1024 ) ) ; $ pow = min ( $ pow , count ( self :: $ sizeUnits ) - 1 ) ; $ bytes /= pow ( 2 , ( 10 * $ pow ) ) ; return sprintf ( '%s %s' , number_format ( round ( $ bytes , 4 * $ decimals ) , $ decimals , $ decimalSeparator , $ thousandsSeparator ) , self :: $ sizeUnits [ $ pow ] ) ; }
Converts an integer with a byte count into human-readable form

@param float|integer $bytes
@param integer $decimals number of decimal places in the resulting string
@param string $decimalSeparator decimal separator of the resulting string
@param string $thousandsSeparator thousands separator of the resulting string
@return string the size string, e.g. "1,024 MB"
Converts an integer with a byte count into human - readable form