PHP 将字节转换为合适的单位显示(MB、GB等)

function byteConvert($bytes)
{
    $s = array('B', 'Kb', 'MB', 'GB', 'TB', 'PB');
    $e = floor(log($bytes) / log(1024));

    return sprintf('%.2f '.$s[$e], ($bytes / pow(1024, $e)));
}

// 例:var_dump(byteConvert(disk_total_space("/")));