From f6d22bca83eb50023cc1cc1d1096249ff83bfde5 Mon Sep 17 00:00:00 2001 From: Pk11 Date: Fri, 10 Feb 2023 23:11:34 -0600 Subject: [PATCH] Show file sizes --- index.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 51f92f2..8d422b7 100644 --- a/index.php +++ b/index.php @@ -209,7 +209,7 @@ $time_rel = time_ago_en($row['post_time']); $time_abs = date('Y-m-d H:m (T)', strtotime($row['post_time'])); - echo '

'; + echo '

'; if((!empty($row['user_id']) && ($row['user_id'] == $_COOKIE['uid'])) || (!empty(ADMIN_ID) && ($_COOKIE['uid'] == ADMIN_ID))) { echo ' '; $show_delete = TRUE; @@ -232,7 +232,12 @@ $ref_result = pg_query_params($ref_query, []) or die('Query failed: ' . pg_last_error()); while($ref = pg_fetch_array($ref_result)) echo ">>{$ref['post_id']} "; - echo '

'; + if(!empty($row['img'])) { + $bytesize = bytesize(filesize(UPLOAD_PATH . $row['img'])); + echo '
File:'; + echo '' . $row['img'] . " ($bytesize)
"; + } + echo '
'; echo '
'; if(!empty($row['img'])){ @@ -245,7 +250,7 @@ if(!empty($row['comment'])) { $comment = $row['comment']; $comment = preg_replace('/^>(?!>\d).+/m', '$0', $comment); - $comment = preg_replace('/(?:https?|mailto|tel|ftp):[^\s]+/m', '$0', $comment); + $comment = preg_replace('/(?:https?|mailto|tel|ftp):[^\s]+/m', '$0', $comment); $comment = preg_replace_callback('/>>\s*(\d+)/', quote_link, $comment); $comment = str_replace("\n", "
", $comment); echo "
$comment
"; @@ -301,6 +306,21 @@ return "{$difference} {$period} {$tense} "; } + // Pretty size for bytes + function bytesize($bytes) { + if($bytes == 1) { + return "1 Byte"; + } else if($bytes < (1 << 10)) { + return "{$bytes} Bytes"; + } else if($bytes < (1 << 20)) { + return round($bytes / (1 << 10), 0) . " KiB"; + } else if($bytes < (1 << 30)) { + return round($bytes / (1 << 20), 0) . " MiB"; + } else { + return round($bytes / (1 << 30), 0) . " GiB"; + } + } + function trip_name($name) { $split = explode('#', $name); $name = array_shift($split);