From b595120d6277f42ffedb9e827c0643e09ea3c503 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 4 Jun 2026 22:06:19 +0000 Subject: [PATCH] =?UTF-8?q?fix(base):=20readableBytes=20=E8=A1=A5=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=A3=B0=E6=98=8E=E5=B9=B6=E4=BF=AE=E6=AD=A3=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E7=B1=BB=E5=9E=8B=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- app/Module/Base.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Module/Base.php b/app/Module/Base.php index 801922714..e3e7928b7 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2818,14 +2818,17 @@ class Base /** * 字节转格式 - * @param $bytes + * @param int|float $bytes * @return string */ - public static function readableBytes($bytes) + public static function readableBytes(int|float $bytes): string { - $i = floor(log($bytes) / log(1024)); + if ($bytes <= 0) { + return '0 B'; + } + $i = (int) floor(log($bytes) / log(1024)); $sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - return sprintf('%.02F', $bytes / pow(1024, $i)) * 1 . ' ' . $sizes[$i]; + return (string) ((float) sprintf('%.02F', $bytes / pow(1024, $i))) . ' ' . $sizes[$i]; } /**