Show file sizes

main
Pk11 2 years ago
parent 768c46f8f4
commit f6d22bca83

@ -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 '<p class="posthead">';
echo '<div class="posthead">';
if((!empty($row['user_id']) && ($row['user_id'] == $_COOKIE['uid'])) || (!empty(ADMIN_ID) && ($_COOKIE['uid'] == ADMIN_ID))) {
echo '<input type="checkbox" name="delete[]" value="' . $row['post_id'] . '" /> ';
$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 "<a href=\"#p{$ref['post_id']}\">&gt;&gt;{$ref['post_id']}</a> ";
echo '</p>';
if(!empty($row['img'])) {
$bytesize = bytesize(filesize(UPLOAD_PATH . $row['img']));
echo '<div>File:';
echo '<a href="' . UPLOAD_PATH . $row['img'] . '" target="_blank">' . $row['img'] . "</a> ($bytesize)</div>";
}
echo '</div>';
echo '<div class="postbody cf">';
if(!empty($row['img'])){
@ -245,7 +250,7 @@
if(!empty($row['comment'])) {
$comment = $row['comment'];
$comment = preg_replace('/^&gt;(?!&gt;\d).+/m', '<strong class="quote">$0</strong>', $comment);
$comment = preg_replace('/(?:https?|mailto|tel|ftp):[^\s]+/m', '<a href="$0">$0</a>', $comment);
$comment = preg_replace('/(?:https?|mailto|tel|ftp):[^\s]+/m', '<a href="$0" target="_blank">$0</a>', $comment);
$comment = preg_replace_callback('/&gt;&gt;\s*(\d+)/', quote_link, $comment);
$comment = str_replace("\n", "<br />", $comment);
echo "<div>$comment</div>";
@ -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);

Loading…
Cancel
Save