mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
feat: Add formatBytes function and update file size display in file import view for terminal page
This commit is contained in:
parent
bba1f47e33
commit
ec67078d49
2 changed files with 26 additions and 1 deletions
25
bootstrap/helpers/filesize.php
Normal file
25
bootstrap/helpers/filesize.php
Normal 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];
|
||||
}
|
||||
|
|
@ -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() }}
|
||||
|
|
|
|||
Loading…
Reference in a new issue