23 lines
627 B
PHP
23 lines
627 B
PHP
<?php
|
|
|
|
if (!function_exists('formatFileSize')) {
|
|
function formatFileSize($fileSizeInBytes): string
|
|
{
|
|
$base = log($fileSizeInBytes) / log(1024);
|
|
$suffix = ["", "k", "M", "G", "T"][floor($base)];
|
|
$size = round(pow(1024, $base - floor($base)), 2);
|
|
return !is_nan($size) ? $size . $suffix : '0B';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('folderSize')) {
|
|
function folderSize($dir): int
|
|
{
|
|
$size = 0;
|
|
foreach (glob(rtrim($dir, '/') . '/*', GLOB_NOSORT) as $each) {
|
|
$size += is_file($each) ? filesize($each) : folderSize($each);
|
|
}
|
|
return $size;
|
|
}
|
|
}
|