/**
* 转换尺寸到友好的单位
* @param float $size 原始尺寸(单位:kb)
* @return float 转换后的尺寸
*/
function transfer_size($size)
{
static $index = 0;
$unit = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'BB'];
if ($size >= 1024) {
$size = round($size/1024, 2);
if ($index < count($unit)) {
$index++;
return transfer_size($size);
}
}
return $size.$unit[$index];
}