From 9cc7e5ff3cdbb40dbee1aedd33418ddb668205fd Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 16 Jul 2026 20:25:18 -0400 Subject: [PATCH] Move Guest Function formatBytes to root shared functions and use in files and files section in contact --- agent/contact.php | 4 ++-- agent/files.php | 8 ++++---- agent/modals/contact/contact.php | 4 ++-- client/functions.php | 13 ------------- functions/format.php | 13 +++++++++++++ 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/agent/contact.php b/agent/contact.php index 111fb629..878865c8 100644 --- a/agent/contact.php +++ b/agent/contact.php @@ -1044,7 +1044,7 @@ if (isset($_GET['contact_id'])) { $file_name = escapeHtml($row['file_name']); $file_description = escapeHtml($row['file_description']); $file_size = escapeHtml($row['file_size']); - $file_size_KB = round($file_size / 1024); + $file_size_human = formatBytes($file_size); $file_mime_type = escapeHtml($row['file_mime_type']); $file_created_at = escapeHtml($row['file_created_at']); @@ -1058,7 +1058,7 @@ if (isset($_GET['contact_id'])) {
- KB + diff --git a/agent/files.php b/agent/files.php index 9054f939..eb9ddbdb 100644 --- a/agent/files.php +++ b/agent/files.php @@ -598,7 +598,7 @@ $num_root_items = intval($row_root_files['num']) + intval($row_root_docs['num']) $file_reference_name= escapeHtml($row['file_reference_name']); $file_ext = escapeHtml($row['file_ext']); $file_size = intval($row['file_size']); - $file_size_KB = number_format($file_size / 1024); + $file_size_human = formatBytes($file_size); $file_mime_type = escapeHtml($row['file_mime_type']); $file_uploaded_by = escapeHtml($row['user_name']); $file_archived_at = escapeHtml($row['file_archived_at']); @@ -722,11 +722,11 @@ $num_root_items = intval($row_root_files['num']) + intval($row_root_docs['num']) $file_reference_name= $item['reference_name']; $file_icon = $item['icon']; $file_size = $item['size']; - $file_size_KB = $file_size ? number_format($file_size / 1024) : 0; + $file_size_human = formatBytes($file_size); $file_mime_type = $item['mime']; $file_uploaded_by = $item['created_by']; $file_created_at = $item['created_at']; - $file_archived_at = $item['archived_at']; + $file_archived_at = $item['archived_at']; // Shared? $sql_shared = mysqli_query( @@ -768,7 +768,7 @@ $num_root_items = intval($row_root_files['num']) + intval($row_root_docs['num']) - KB +
diff --git a/agent/modals/contact/contact.php b/agent/modals/contact/contact.php index 9807c735..eef8d87c 100644 --- a/agent/modals/contact/contact.php +++ b/agent/modals/contact/contact.php @@ -825,7 +825,7 @@ ob_start(); $file_name = escapeHtml($row['file_name']); $file_description = escapeHtml($row['file_description']); $file_size = escapeHtml($row['file_size']); - $file_size_KB = round($file_size / 1024); + $file_size_human = formatBytes($file_size); $file_mime_type = escapeHtml($row['file_mime_type']); $file_created_at = escapeHtml($row['file_created_at']); @@ -839,7 +839,7 @@ ob_start();
- KB + 1024 && $i < count($units) - 1; $i++) { - $bytes /= 1024; - } - - return round($bytes, $precision) . ' ' . $units[$i]; -} diff --git a/functions/format.php b/functions/format.php index bc719028..d400d65f 100644 --- a/functions/format.php +++ b/functions/format.php @@ -328,3 +328,16 @@ function validateDate($date) { } return date('Y-m-d'); // Fallback } + +/* + * Formats bytes into human readable file sizes + */ +function formatBytes($bytes, $precision = 2) { + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + + for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) { + $bytes /= 1024; + } + + return round($bytes, $precision) . ' ' . $units[$i]; +}