فهرست منبع

added humanFileSize

Piotr Labudda 9 سال پیش
والد
کامیت
f79499b83c
1فایلهای تغییر یافته به همراه19 افزوده شده و 0 حذف شده
  1. 19 0
      SE/se-lib/V.php

+ 19 - 0
SE/se-lib/V.php

@@ -416,4 +416,23 @@ EOF';
 		return $arr;
 	}
 
+	public function humanFileSize($bytes) {
+		$bytes = intval($bytes);
+		$arBytes = array(
+			0 => array("UNIT" => "TB", "VALUE" => pow(1024, 4)),
+			1 => array("UNIT" => "GB", "VALUE" => pow(1024, 3)),
+			2 => array("UNIT" => "MB", "VALUE" => pow(1024, 2)),
+			3 => array("UNIT" => "KB", "VALUE" => 1024),
+			4 => array("UNIT" => "B",  "VALUE" => 1)
+		);
+		foreach($arBytes as $arItem) {
+			if ($bytes >= $arItem["VALUE"]) {
+				$result = $bytes / $arItem["VALUE"];
+				$result = str_replace(".", "," , strval(round($result, 2)))." ".$arItem["UNIT"];
+				break;
+			}
+		}
+		return $result;
+	}
+
 }