| @@ 20-30 (lines=11) @@ | ||
| 17 | /* |
|
| 18 | * Source https://stackoverflow.com/questions/2510434/format-bytes-to-kilobytes-megabytes-gigabytes |
|
| 19 | */ |
|
| 20 | private function formatBytes($bytes, $precision = 2): string |
|
| 21 | { |
|
| 22 | $units = ['B', 'KB', 'MB', 'GB', 'TB']; |
|
| 23 | ||
| 24 | $bytes = max($bytes, 0); |
|
| 25 | $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); |
|
| 26 | $pow = min($pow, count($units) - 1); |
|
| 27 | $bytes /= (1 << (10 * $pow)); |
|
| 28 | ||
| 29 | return round($bytes, $precision) . ' ' . $units[$pow]; |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| @@ 44-54 (lines=11) @@ | ||
| 41 | /* |
|
| 42 | * Source https://stackoverflow.com/questions/2510434/format-bytes-to-kilobytes-megabytes-gigabytes |
|
| 43 | */ |
|
| 44 | private function formatBytes($bytes, $precision = 2): string |
|
| 45 | { |
|
| 46 | $units = ['B', 'KB', 'MB', 'GB', 'TB']; |
|
| 47 | ||
| 48 | $bytes = max($bytes, 0); |
|
| 49 | $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); |
|
| 50 | $pow = min($pow, count($units) - 1); |
|
| 51 | $bytes /= (1 << (10 * $pow)); |
|
| 52 | ||
| 53 | return round($bytes, $precision) . ' ' . $units[$pow]; |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||