Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP: Format bytes into a human readable format
// convert bytes format
function format_Bytes($size,$level=0,$precision=2,$base=1024)
{
if ($size === '0' || $size === null) {
return "0 B";
}
else
$unit = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB','YB');
$times = floor(log($size,$base));
return sprintf("%.".$precision."f",$size/pow($base,($times+$level)))." ".$unit[$times+$level];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.