4个字节生成一个字节校验
Whenever you manage disk space, it's infinitely easier to read when when the bytes are displayed in KB, MB, GB... format. When reading files on the disk, the server returns the disk space in bytes so it's on us programmers to program file sizes for display. Using PHP, this task is cake.
无论何时管理磁盘空间,当字节以KB,MB,GB ...格式显示时,读取都将无限地容易。 当读取磁盘上的文件时,服务器返回磁盘空间(以字节为单位),因此程序员可以编程文件大小以进行显示。 使用PHP,这个任务很简单。
function format_bytes($bytes)
{
$labels = array('B','KB','MB','GB','TB');
for($x = 0; $bytes >= 1024 && $x < (count($labels) - 1); $bytes /= 1024, $x++);
return(round($bytes, 2).' '.$labels[$x]);
}
Users will appreciate this!
用户将不胜感激!
翻译自: https://davidwalsh.name/generate-readable-byte-labels-using-php
4个字节生成一个字节校验