Kaynağa Gözat

Merge pull request #1643 from Gelaku/patch-7

添加全局字节单位转换
Jiang Qinghua 3 yıl önce
ebeveyn
işleme
1bd1189bbd
1 değiştirilmiş dosya ile 22 ekleme ve 0 silme
  1. 22 0
      src/Support/helpers.php

+ 22 - 0
src/Support/helpers.php

@@ -571,3 +571,25 @@ if (! function_exists('admin_redirect')) {
         return Helper::redirect($to, $statusCode, $request);
     }
 }
+
+if (! function_exists('format_byte')) {
+    /**
+     * 文件单位换算.
+     *
+     * @param $input
+     * @param  int  $dec
+     * @return string
+     */
+    function format_byte($input, $dec = 0)
+    {
+        $prefix_arr = ['B', 'KB', 'MB', 'GB', 'TB'];
+        $value = round($input, $dec);
+        $i = 0;
+        while ($value > 1024) {
+            $value /= 1024;
+            $i++;
+        }
+
+        return round($value, $dec).$prefix_arr[$i];
+    }
+}