Even nicer is this version I created from a plugin I found:
function filesize_formatted($path)
{
$size = filesize($path);
$units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
}
Note from filesize() doc
Because PHP's integer type is signed and many platforms use 32bit
integers, some filesystem functions may return unexpected results for
files which are larger than 2GB