新增字节自动格式化易读单位
This commit is contained in:
@@ -387,4 +387,27 @@ final class Util
|
||||
|
||||
return [$content, $filePath];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字节自动格式化易读单位
|
||||
* @param float $bytes
|
||||
* @return string
|
||||
*/
|
||||
public static function prettyBytes(float $bytes): string
|
||||
{
|
||||
$step = pow(1024, 4);
|
||||
if ($bytes >= $step) {
|
||||
return round($bytes / $step, 2) . 'TB';
|
||||
}
|
||||
$step = pow(1024, 3);
|
||||
if ($bytes >= $step) {
|
||||
return round($bytes / $step, 2) . 'GB';
|
||||
}
|
||||
$step = pow(1024, 2);
|
||||
if ($bytes >= $step) {
|
||||
return round($bytes / $step, 2) . 'MB';
|
||||
}
|
||||
$step = 1024;
|
||||
return round($bytes / $step, 2) . 'KB';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user