F::niceSize PHP Method

niceSize() public static method

$niceSize = f::niceSize('/path/to/a/file.txt'); nice size is i.e: 212 kb $niceSize = f::niceSize(1231939); nice size is: 1,2 mb
public static niceSize ( mixed $size ) : string
$size mixed The file size or a file path
return string
    public static function niceSize($size)
    {
        // file mode
        if (is_string($size) && file_exists($size)) {
            $size = static::size($size);
        }
        // make sure it's an int
        $size = (int) $size;
        // avoid errors for invalid sizes
        if ($size <= 0) {
            return '0 kB';
        }
        // the math magic
        return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . static::$units[$i];
    }