Initial commit: Cloud Control Panel
This commit is contained in:
23
src/Helpers/helpers.php
Normal file
23
src/Helpers/helpers.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
if (!function_exists('formatBytes')) {
|
||||
|
||||
function formatBytes(int $bytes): string
|
||||
{
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$i = 0;
|
||||
|
||||
while ($bytes >= 1024 && $i < count($units) - 1) {
|
||||
$bytes /= 1024;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return round($bytes, 1) . ' ' . $units[$i];
|
||||
}
|
||||
}
|
||||
if (!function_exists('getStoragePercent')) {
|
||||
function getStoragePercent(int $categoryBytes, int $totalBytes): float
|
||||
{
|
||||
return $totalBytes > 0 ? ($categoryBytes / $totalBytes * 100) : 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user