作用:当用户在非当前网站使用附件内的图片时,显示自己指定的图片。
修改文件,打开 attachment.php
查找函数:
function showattachment()
将这个函数全部替换为:
(请注意这个函数内的
$filename = 'mypic.gif'; //在这里填写你的URL地址 更改为你要使用的图片,并传到 data/updalds[上传附件文件夹]内)
:
function showattachment()
{
global $DB, $forums, $_INPUT, $bbuserinfo, $bboptions;
$forums->noheader = 1;
$filename = $_INPUT['filename'];
$extension = $_INPUT['extension'];
$update=TRUE;
$url=parse_url($_SERVER['HTTP_REFERER']);
if ($url['host']!=$_SERVER['HTTP_HOST'] AND in_array($forums->cache['attachmenttype'][ $extension ]['mimetype'], array( 'gif', 'jpeg', 'jpg', 'png' ))) {
$filename = 'mypic.gif'; //在这里填写你的URL地址
$extension = $av_ext = preg_replace( "/^.*.(S+)$/", "1", $filename );
$files = $bboptions['uploadfolder'].'/'.$filename;
$noupdate=FALSE;
} else {
if (!$_INPUT['u'] OR !$_INPUT['attach']) {
$forums->func->standard_error("cannotviewattach");
}
if (!$bbuserinfo['candownload']) {
$forums->func->standard_error("cannotdownload");
}
$subpath = SAFE_MODE ? "" : implode('/', preg_split('//', intval($_INPUT['u']), -1, PREG_SPLIT_NO_EMPTY));
$subpath = trim($_INPUT['attachpath']) ? $subpath : '';
$path = $bboptions['uploadfolder'] . '/' . $subpath;
$_INPUT['attach'] = str_replace( "/", "", substr( $_INPUT['attach'], strrpos( $_INPUT['attach'], '/' ) ) );
$files = "e:/www/mxb/data/uploads/mypic.gif";
}
if ( file_exists( $files ) AND ( $forums->cache['attachmenttype'][ $extension ]['mimetype'] != "" ) ) {
if($update) {
$DB->shutdown_query("UPDATE ".TABLE_PREFIX."attachment SET counter=counter+1 WHERE attachmentid=".intval($_INPUT['id'])."");
}
@header('Cache-control: max-age=31536000');
@header('Expires: ' . gmdate("D, d M Y H:i:s", TIMENOW + 31536000) . ' GMT');
@header( 'Content-Type: '.$forums->cache['attachmenttype'][ $extension ]['mimetype'].'' );
@header( 'Content-Disposition: inline; filename='.$filename.'' );
@header( 'Content-Disposition: inline; filename='.$filename.'' );
@header( 'Content-Length: '.(string)(filesize( $files ) ).'' );
$fh = fopen( $files, 'rb' );
fpassthru( $fh );
@fclose( $fh );
exit();
} else {
$forums->func->standard_error("cannotviewattach");
}
}
上传修改过的文件,完成