From 2ffa6c130c0a6d834220af98db917cd5bcae6336 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 1 Feb 2018 21:27:34 -0500 Subject: [PATCH] Show attachment size in attachment info --- admin/admin_ticket.php | 4 ++-- inc/common.inc.php | 25 +++++++++++++++++++++++++ inc/view_attachment_functions.inc.php | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/admin/admin_ticket.php b/admin/admin_ticket.php index 36804051..b180ab34 100644 --- a/admin/admin_ticket.php +++ b/admin/admin_ticket.php @@ -1193,9 +1193,9 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); echo ' - + - ' . $att_name . '
+ ' . $att_name . ' (' . mfh_getAttachmentFileSize($att_id) . ')' . '
'; } } diff --git a/inc/common.inc.php b/inc/common.inc.php index b6ce26f9..e2821a7e 100644 --- a/inc/common.inc.php +++ b/inc/common.inc.php @@ -2131,6 +2131,31 @@ function mfh_getNumberOfDownloadsForAttachment($att_id, $table = 'attachments') return $rec['download_count']; } +function mfh_getAttachmentFileSize($att_id, $table = 'attachments') { + global $hesk_settings; + + $res = hesk_dbQuery('SELECT `size` FROM `' . hesk_dbEscape($hesk_settings['db_pfix'] . $table) . "` WHERE `att_id` = " . intval($att_id)); + $rec = hesk_dbFetchAssoc($res); + return human_filesize($rec['size']); +} + +function human_filesize($bytes, $decimals = 2) { + global $hesklang; + + $sz = 'BKMGTP'; + $factor = floor((strlen($bytes) - 1) / 3); + + if ($factor < strlen($sz)) { + $factorName = @$sz[$factor]; + if ($factorName !== 'B') { + $factorName .= 'B'; + } + + return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . $factorName; + } + return $hesklang['unknown']; +} + function mfh_getSettings() { global $hesk_settings; diff --git a/inc/view_attachment_functions.inc.php b/inc/view_attachment_functions.inc.php index 3aee6e88..df2a45b9 100644 --- a/inc/view_attachment_functions.inc.php +++ b/inc/view_attachment_functions.inc.php @@ -24,6 +24,7 @@ function mfh_listAttachments($attachments = '', $reply = 0, $is_staff) if ($is_staff) { echo '' . $hesklang['download_count'] . ''; } + echo '' . 'File size' . ''; echo '' . $hesklang['action'] . ' '; @@ -72,6 +73,7 @@ function mfh_listAttachments($attachments = '', $reply = 0, $is_staff) if ($is_staff) { echo '' . mfh_getNumberOfDownloadsForAttachment($att_id) . ''; } + echo '' . mfh_getAttachmentFileSize($att_id) . ''; echo '
'; /* Can edit and delete tickets? */