Commit ea523045 authored by 王源's avatar 王源 🎧

优化文件大小转化方法

parent fa6370a1
...@@ -380,17 +380,20 @@ if (!function_exists('num_2_file_size')) { ...@@ -380,17 +380,20 @@ if (!function_exists('num_2_file_size')) {
function num_2_file_size($num) function num_2_file_size($num)
{ {
$p = 0; $p = 0;
$format = 'KB'; $format = 'B';
if ($num > 0 && $num < 1024) { if ($num > 0 && $num < 1024) {
return number_format($num) . ' ' . $format; return number_format($num) . ' ' . $format;
} else if ($num >= 1024 && $num < pow(1024, 2)) { } else if ($num >= 1024 && $num < pow(1024, 2)) {
$p = 1; $p = 1;
$format = 'MB'; $format = 'KB';
} else if ($num >= pow(1024, 2) && $num < pow(1024, 3)) { } else if ($num >= pow(1024, 2) && $num < pow(1024, 3)) {
$p = 2; $p = 2;
$format = 'GB'; $format = 'MB';
} else if ($num >= pow(1024, 3) && $num < pow(1024, 4)) { } else if ($num >= pow(1024, 3) && $num < pow(1024, 4)) {
$p = 3; $p = 3;
$format = 'GB';
} else if ($num >= pow(1024, 4) && $num < pow(1024, 5)) {
$p = 4;
$format = 'TB'; $format = 'TB';
} }
$num /= pow(1024, $p); $num /= pow(1024, $p);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment