Added helper file, replaced size file for human version as a helper method, next prev buttons for chapters.

This commit is contained in:
Krzysztof Płaczek
2022-12-07 11:37:50 +01:00
parent b992d05312
commit 25e28f8193
7 changed files with 82 additions and 16 deletions

22
app/helpers.php Normal file
View File

@@ -0,0 +1,22 @@
<?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;
}
}