By default only links are shown for image attachments accessed via Administration Center » Attachments and Avatars » Browse Files. The following code change displays a thumbnail sized (ie, max 150px x 150px) view of images above the link.
In ./Sources/ManageAttachments.php:
Find:
global $modSettings, $context, $scripturl;
$link = \'<a href="\';
// In case of a custom avatar URL attachments have a fixed directory.
if ($rowData[\'attachment_type\'] == 1)
$link .= sprintf(\'%1$s/%2$s\', $modSettings[\'custom_avatar_url\'], $rowData[\'filename\']);
// By default avatars are downloaded almost as attachments.
elseif ($context[\'browse_type\'] == \'avatars\')
$link .= sprintf(\'%1$s?action=dlattach;type=avatar;attach=%2$d\', $scripturl, $rowData[\'id_attach\']);
// Normal attachments are always linked to a topic ID.
else
$link .= sprintf(\'%1$s?action=dlattach;topic=%2$d.0;attach=%3$d\', $scripturl, $rowData[\'id_topic\'], $rowData[\'id_attach\']);
$link .= \'"\';
// Show a popup on click if it\'s a picture and we know its dimensions.
if (!empty($rowData[\'width\']) && !empty($rowData[\'height\']))
$link .= sprintf(\' onclick="return reqWin(this.href\' . ($rowData[\'attachment_type\'] == 1 ? \'\' : \' + \\\';image\\\'\') . \', %1$d, %2$d, true);"\', $rowData[\'width\'] + 20, $rowData[\'height\'] + 20);
$link .= sprintf(\'>%1$s</a>\', preg_replace(\'~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~\', \'&#\\\\1;\', htmlspecialchars($rowData[\'filename\'])));
// Show the dimensions.
if (!empty($rowData[\'width\']) && !empty($rowData[\'height\']))
$link .= sprintf(\' <span class="smalltext">%1$dx%2$d</span>\', $rowData[\'width\'], $rowData[\'height\']);
return $link;
Replace With:
global $modSettings, $context, $scripturl;
// Work out if this is an image.
$isImage = (!empty($rowData[\'width\']) && !empty($rowData[\'height\']));
// In case of a custom avatar URL attachments have a fixed directory.
if ($rowData[\'attachment_type\'] == 1)
$attLink = sprintf(\'%1$s/%2$s\', $modSettings[\'custom_avatar_url\'], $rowData[\'filename\']);
// By default avatars are downloaded almost as attachments.
elseif ($context[\'browse_type\'] == \'avatars\')
$attLink = sprintf(\'%1$s?action=dlattach;type=avatar;attach=%2$d\', $scripturl, $rowData[\'id_attach\']);
// Normal attachments are always linked to a topic ID.
else
$attLink = sprintf(\'%1$s?action=dlattach;topic=%2$d.0;attach=%3$d\', $scripturl, $rowData[\'id_topic\'], $rowData[\'id_attach\']);
$link = \'<a href="\' . $attLink . \'"\';
// Show a popup on click if it\'s a picture and we know its dimensions.
// Also show a thumbnail sized view of the image.
if ($isImage)
$link .= sprintf(\' onclick="return reqWin(this.href\' . ($rowData[\'attachment_type\'] == 1 ? \'\' : \' + \\\';image\\\'\') . \', %1$d, %2$d, true);"\', $rowData[\'width\'] + 20, $rowData[\'height\'] + 20) . sprintf(\'><img style="width: auto; height: auto; max-width: 150px; max-height: 150px;" src="\'. $attLink . \'"><br /\');
$link .= sprintf(\'>%1$s</a>\', preg_replace(\'~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~\', \'&#\\\\1;\', htmlspecialchars($rowData[\'filename\'])));
// Show the dimensions.
if ($isImage)
$link .= sprintf(\' <span class="smalltext">%1$dx%2$d</span>\', $rowData[\'width\'], $rowData[\'height\']);
return $link;
A similar solution can also be implemented for unapproved attachments (with the addition of download links for all attachment types):
In ./Sources/PostModeration.php
Find:
// Get all unapproved attachments.
$request = $smcFunc['db_query']('', '
SELECT a.id_attach, a.filename,
Add After:
a.width, a.height,
Find:
$context['unapproved_items'][] = array(
'id' => $row['id_attach'],
'alternate' => $i % 2,
'filename' => $row['filename'],
Add After:
'isImage' => (!empty($row['width']) && !empty($row['height']) ? true : false),
'attLink' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'],
In ./Themes/default/ModerationCenter.template.php
Find:
<td>
', $item['filename'], '
</td>
Replace With:
<td>
', '<a href="' . $item['attLink'] . ($item['isImage'] ? ';image"><img style="width: auto; height: auto; max-width: 150px; max-height: 150px;" src="' . $item['attLink'] . '"><br />' : '">') . $item['filename'] . '</a>', '
</td>