summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-06-07 00:25:25 +0400
committerilotterytea <iltsu@alright.party>2025-06-07 00:25:25 +0400
commit371d863870520da9a4f3383d7c52e1720c074d03 (patch)
tree1e86c3d0a18d594f77065a171cdf0de7ab1e3825 /public
parent6d2e279190484d48ffa3a73e691bda003fcba0c9 (diff)
fix: filesize display
Diffstat (limited to 'public')
-rw-r--r--public/index.php20
1 files changed, 5 insertions, 15 deletions
diff --git a/public/index.php b/public/index.php
index f5ea820..580a186 100644
--- a/public/index.php
+++ b/public/index.php
@@ -71,22 +71,12 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) {
$file['full_url'] = FILE_UPLOAD_DIRECTORY_PREFIX . "/{$file['id']}.{$file['extension']}";
+ // formatting the file size
$size = $file['size'];
- $size_suffix = 'B';
- $size_i = 0;
- do {
- $size /= 1024;
- $size_suffix = match ($size_i) {
- 0 => 'B',
- 1 => 'KB',
- 2 => 'MB',
- 3 => 'GB',
- default => 'TB'
- };
- $size_i++;
- } while ($size > 1024);
-
- $file['size_formatted'] = sprintf('%.2f%s', $size, $size_suffix);
+ $units = ['B', 'KB', 'MB', 'GB', 'TB'];
+ $factor = floor((strlen($size) - 1) / 3);
+ $file['size_formatted'] = sprintf("%.2f", $size / pow(1024, $factor)) . ' ' . $units[$factor];
+
$file['name'] = $file['original_name'] ?? sprintf('%s.%s', $file['id'], $file['extension']);
if (!isset($file['uploaded_at'])) {