feat: Add formatBytes function and update file size display in file import view for terminal page

This commit is contained in:
Ahliman HUSEYNOV 2025-11-13 15:54:07 +01:00
parent bba1f47e33
commit ec67078d49
No known key found for this signature in database
2 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,25 @@
<?php
/**
* Format bytes to human-readable size
*
* @param int|float $bytes The size in bytes
* @param int $precision The number of decimal places
* @return string Formatted size with unit (B, KB, MB, GB, TB)
*/
function formatBytes($bytes, int $precision = 2): string
{
$bytes = (int) $bytes;
if ($bytes < 1024) {
return $bytes . ' B';
}
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
$exp = floor(log($bytes) / log(1024));
$exp = min($exp, count($units) - 1);
$value = $bytes / pow(1024, $exp);
return round($value, $precision) . ' ' . $units[$exp];
}

View file

@ -161,7 +161,7 @@
@endif
</td>
<td class="py-3 pr-4">
{{ number_format($file['size'] / 1024 / 1024, 2) }} MB
{{ formatBytes($file['size']) }}
</td>
<td class="py-3 pr-4">
{{ \Carbon\Carbon::createFromTimestamp($file['uploaded_at'])->diffForHumans() }}