📄 attachment.php
字号:
<?php
/*
[DISCUZ!] attachment.php - attachment downloading
This is NOT a freeware, use is subject to license terms
Version: 4.0.0
Web: http://www.comsenz.com
Copyright: 2001-2005 Comsenz Technology Ltd.
Last Modified: 2004/10/21 01:33
*/
require_once './include/common.inc.php';
$discuz_action = 14;
if($attachrefcheck && preg_replace("/https?:\/\/([^\/]+).*/i", "\\1", $HTTP_SERVER_VARS['HTTP_REFERER']) != $HTTP_SERVER_VARS['HTTP_HOST']) {
showmessage('attachment_referer_invalid', NULL, 'HALTED');
}
$query = $db->query("SELECT a.*, t.fid FROM {$tablepre}attachments a, {$tablepre}threads t, {$tablepre}posts p
WHERE a.aid='$aid' AND t.tid=a.tid AND p.pid=a.pid AND t.displayorder>='0' AND p.invisible='0'");
$attach = $db->fetch_array($query);
if($allowgetattach && $attach['creditsrequire'] && $attach['creditsrequire'] > $credits && $adminid <= 0) {
showmessage('attachment_nopermission', NULL, 'NOPERM');
}
$filename = $attachdir.'/'.$attach['attachment'];
if(is_readable($filename) && $attach) {
$query = $db->query("SELECT f.getattachperm, a.allowgetattach FROM {$tablepre}forumfields f
LEFT JOIN {$tablepre}access a ON a.uid='$discuz_uid' AND a.fid=f.fid
WHERE f.fid='$attach[fid]'");
$forum = $db->fetch_array($query);
if(!$forum['allowgetattach']) {
if(!$forum['getattachperm'] && !$allowgetattach) {
showmessage('group_nopermission', NULL, 'NOPERM');
} elseif($forum['getattachperm'] && !strstr($forum['getattachperm'], "\t$groupid\t")) {
showmessage('attachment_forum_nopermission', NULL, 'NOPERM');
}
}
$db->query("UPDATE {$tablepre}attachments SET downloads=downloads+1 WHERE aid='$aid'", 'UNBUFFERED');
$filesize = filesize($filename);
ob_end_clean();
header('Cache-control: max-age=31536000');
header('Expires: '.gmdate('D, d M Y H:i:s', $timestamp + 31536000).' GMT');
header('Content-Encoding: none');
header('Content-Length: '.$filesize);
//forbid flash be opened directly
//header('Content-Disposition: '.(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE') ? 'inline; ' : 'attachment; ').'filename='.$attach['filename']);
header('Content-Disposition: attachment; filename='.$attach['filename']);
header('Content-Type: '.$attach['filetype']);
@$fp = fopen($filename, 'rb');
@flock($fp, 2);
$attachment = @fread($fp, $filesize);
@fclose($fp);
echo $attachment;
} else {
showmessage('attachment_nonexistence');
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -