Puddinq.com sharing knowledge

Make output php filesize readable for humans

Make output php filesize readable for humans

$bytes = filesize($file);

if ($bytes == 0)
    return "0.00 B";

$s = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
$e = floor(log($bytes, 1024));

echo round($bytes/pow(1024, $e), 2).$s[$e];