вопрос
Подскажите как вывести размер загруженного файла в полной новости не прописывая вручную размер в доп поле. Дело в том, что гостям запрещено скачивания файлов и соответственно атачмент не отображается с размером.
Ответил: vitnet
engine/modules/functions.php
function show_attach($story, $id, $static = false) {
global $db, $config, $lang, $user_group, $member_id;
$find_1 = array();
$find_2 = array();
$replace_1 = array();
$replace_2 = array();
if( $static ) {
if( is_array( $id ) and count( $id ) ) $where = "static_id IN (" . implode( ",", $id ) . ")";
else $where = "static_id = '".intval($id)."'";
$db->query( "SELECT id, name, onserver, dcount FROM " . PREFIX . "_static_files WHERE $where" );
$area = "&area=static";
} else {
if( is_array( $id ) and count( $id ) ) $where = "news_id IN (" . implode( ",", $id ) . ")";
else $where = "news_id = '".intval($id)."'";
$db->query( "SELECT id, name, onserver, dcount FROM " . PREFIX . "_files WHERE $where" );
$area = "";
}
while ( $row = $db->get_row() ) {
$size = formatsize( @filesize( ROOT_DIR . '/uploads/files/' . $row['onserver'] ) );
$row['name'] = explode( "/", $row['name'] );
$row['name'] = end( $row['name'] );
$find_1[] = '[attachment=' . $row['id'] . ']';
$find_2[] = "#\[attachment={$row['id']}:(.+?)\]#i";
if ( !$user_group[$member_id['user_group']]['allow_files'] ) {
$replace_1[] = "<span class=\"attachment\">{$lang['att_denied']}</span>" . $size; // <-- размер
$replace_2[] = "<span class=\"attachment\">{$lang['att_denied']}</span>" . $size; // <-- размер
} elseif( $config['files_count'] == 'yes' ) {
$replace_1[] = "<span class=\"attachment\"><a href=\"{$config['http_home_url']}engine/download.php?id={$row['id']}{$area}\" onclick=\"Download('{$row['id']}'); return false;\">{$row['name']}</a> [{$size}] ({$lang['att_dcount']} {$row['dcount']})</span>";
$replace_2[] = "<span class=\"attachment\"><a href=\"{$config['http_home_url']}engine/download.php?id={$row['id']}{$area}\">\\1</a> [{$size}] ({$lang['att_dcount']} {$row['dcount']})</span>";
} else {
$replace_1[] = "<span class=\"attachment\"><a href=\"{$config['http_home_url']}engine/download.php?id={$row['id']}{$area}\" onclick=\"Download('{$row['id']}'); return false;\">{$row['name']}</a> [{$size}]</span>";
$replace_2[] = "<span class=\"attachment\"><a href=\"{$config['http_home_url']}engine/download.php?id={$row['id']}{$area}\" >\\1</a> [{$size}]</span>";
}
}
$db->free();
$story = str_replace ( $find_1, $replace_1, $story );
$story = preg_replace( $find_2, $replace_2, $story );
return $story;
}