function formatBytes($bytes) {
if($bytes >= 1073741824) {
$bytes = round($bytes / 1073741824 * 100) / 100 . 'GB';
} elseif($bytes >= 1048576) {
$bytes = round($bytes / 1048576 * 100) / 100 . 'MB';
} elseif($bytes >= 1024) {
$bytes = round($bytes / 1024 * 100) / 100 . 'KB';
} else {
$bytes = $bytes . 'Bytes';
}
return $bytes;
}
/**
* 字节格式化 把字节数格式为 B K M G T 描述的大小
* @return string
*/
function byte_format($size, $dec=2) {
$a = array("B", "KB", "MB", "GB", "TB", "PB");
$pos = 0;
while ($size >= 1024) {
$size /= 1024;
$pos++;
}
return round($size,$dec)." ".$a[$pos];
}