Discuz! 5.0.0论坛程序中加入一段js代码,让会员点击下载附件前自动弹出提示窗口


Posted in PHP onApril 18, 2007

你需要修改attachment.php文件 在根目录下 
在$attachexists = $ispaid = FALSE;下面添加 
if (!empty($checktwo)) { 
在最末尾的?>前添加 
} else { 
echo "<script>alert('写上你要提示的内容')</script>"; 
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=$PHP_SELF?checktwo=1&aid=$aid\">"; 

我在本机架设Discuz! 5.0.1调试通过了 
完整代码如下: 
<?php 
/* 
[Discuz!] (C)2001-2006 Comsenz Inc. 
This is NOT a freeware, use is subject to license terms 
$RCSfile: attachment.php,v $ 
$Revision: 1.13 $ 
$Date: 2006/08/11 06:51:07 $ 
*/ 
require_once './include/common.inc.php'; 
$discuz_action = 14; 
if($attachrefcheck && $_SERVER['HTTP_REFERER'] && preg_replace("/https?:\/\/([^\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) != $_SERVER['HTTP_HOST']) { 
//header("Location: {$boardurl}images/common/invalidreferer.gif"); 
showmessage('attachment_referer_invalid', NULL, 'HALTED'); 

/* 
$query = $db->query("SELECT a.*, t.fid, p.authorid 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); 
*/ 
periodscheck('attachbanperiods'); 
$attachexists = $ispaid = FALSE; 
if (!empty($checktwo)) { 
if(!empty($aid)) { 
$query = $db->query("SELECT * FROM {$tablepre}attachments WHERE aid='$aid'"); 
if($attach = $db->fetch_array($query)) { 
$query = $db->query("SELECT tid, fid, price, special FROM {$tablepre}threads WHERE tid='$attach[tid]' AND displayorder>='0'"); 
$thread = $db->fetch_array($query); 
if($thread['fid']) { 
$query = $db->query("SELECT authorid FROM {$tablepre}posts WHERE pid='$attach[pid]' AND invisible='0'"); 
if($db->num_rows($query)) { 
$attach['authorid'] = $db->result($query, 0); 
$attachexists = TRUE; 




if($allowgetattach && ($attach['readperm'] && $attach['readperm'] > $readaccess) && $adminid <= 0 && !($discuz_uid && $discuz_uid == $attach['authorid'])) { 
showmessage('attachment_forum_nopermission', NULL, 'NOPERM'); 

if(!$thread['special'] && $thread['price'] > 0 && (!$discuz_uid || ($discuz_uid && $discuz_uid != $attach['authorid'] && $adminid <=0))) { 
$query = $db->query("SELECT uid FROM {$tablepre}paymentlog WHERE uid='$discuz_uid' AND tid='$attach[tid]'"); 
if($db->result($query, 0)) { 
$ispaid = TRUE; 
} else { 
showmessage('attachment_payto', 'viewthread.php?tid='.$attach['tid']); 


$filename = $attachdir.'/'.$attach['attachment']; 
if(is_readable($filename) && $attachexists) { 
$query = $db->query("SELECT f.viewperm, f.getattachperm, f.getattachcredits, a.allowgetattach FROM {$tablepre}forumfields f 
LEFT JOIN {$tablepre}access a ON a.uid='$discuz_uid' AND a.fid=f.fid 
WHERE f.fid='$thread[fid]'"); 
$forum = $db->fetch_array($query); 
if(!$ispaid) { 
if(!$forum['allowgetattach']) { 
if(!$forum['getattachperm'] && !$allowgetattach) { 
showmessage('group_nopermission', NULL, 'NOPERM'); 
} elseif(($forum['getattachperm'] && !forumperm($forum['getattachperm'])) || ($forum['viewperm'] && !forumperm($forum['viewperm']))) { 
showmessage('attachment_forum_nopermission', NULL, 'NOPERM'); 



if(!($isimage = preg_match("/^image\/.+/", $attach['filetype']))) { 
checklowerlimit($creditspolicy['getattach'], -1); 

if(empty($noupdate)) { 
if($delayviewcount == 2 || $delayviewcount == 3) { 
$logfile = './forumdata/cache/cache_attachviews.log'; 
if(substr($timestamp, -1) == '0') { 
require_once DISCUZ_ROOT.'./include/misc.func.php'; 
updateviews('attachments', 'aid', 'downloads', $logfile); 

if(@$fp = fopen(DISCUZ_ROOT.$logfile, 'a')) { 
fwrite($fp, "$aid\n"); 
fclose($fp); 
} elseif($adminid == 1) { 
showmessage('view_log_invalid'); 

} else { 
$db->query("UPDATE {$tablepre}attachments SET downloads=downloads+'1' WHERE aid='$aid'", 'UNBUFFERED'); 


if(!$isimage) { 
$forum['getattachcredits'] = $forum['getattachcredits'] ? unserialize($forum['getattachcredits']) : array(); 
$getattachcredits = $forum['getattachcredits'] ? $forum['getattachcredits'] : $creditspolicy['getattach']; 
updatecredits($discuz_uid, $getattachcredits, -1); 

$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'); 
$attach['filename'] = (strtolower($charset) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? urlencode($attach['filename']) : $attach['filename']; 
if($isimage && !empty($noupdate)) { 
header('Content-Disposition: inline; filename='.$attach['filename']); 
} else { 
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'); 

} else { 
echo "<script>alert('$PHP_SELF')</script>"; 
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=$PHP_SELF?checktwo=1&aid=$aid\">"; 

?> 

PHP 相关文章推荐
PHP 基本语法格式
Dec 15 PHP
php 使用post,get的一种简洁方式
Apr 25 PHP
php获取从百度搜索进入网站的关键词的详细代码
Jan 08 PHP
VPS中使用LNMP安装WordPress教程
Dec 28 PHP
php线性表的入栈与出栈实例分析
Jun 12 PHP
php项目中百度 UEditor 简单安装调试和调用
Jul 15 PHP
jQuery+PHP发布的内容进行无刷新分页(Fckeditor)
Oct 22 PHP
PHP 开发者该知道的 5 个 Composer 小技巧
Feb 03 PHP
thinkPHP分页功能实例详解
May 05 PHP
php静态成员方法和静态的成员属性的使用方法
Oct 26 PHP
PHP超低内存遍历目录文件和读取超大文件的方法
May 01 PHP
PHP实现创建一个RPC服务操作示例
Feb 23 PHP
PHP和XSS跨站攻击的防范
Apr 17 #PHP
PHP与SQL注入攻击[三]
Apr 17 #PHP
PHP与SQL注入攻击[二]
Apr 17 #PHP
PHP与SQL注入攻击[一]
Apr 17 #PHP
使用Xdebug调试和优化PHP程序之[1]
Apr 17 #PHP
php下用GD生成生成缩略图的两个选择和区别
Apr 17 #PHP
15种PHP Encoder的比较
Apr 17 #PHP
You might like
重量级动漫纷纷停播!唯独OVERLORD第四季正在英魂之刃继续更新
2020/05/06 日漫
PHP 替换模板变量实现步骤
2009/08/24 PHP
Wordpress 相册插件 NextGEN-Gallery 添加目录将中文转为拼音的解决办法
2010/12/29 PHP
php文件上传表单摘自drupal的代码
2011/02/15 PHP
第四章 php数学运算
2011/12/30 PHP
Yii中CGridView关联表搜索排序方法实例详解
2014/12/03 PHP
php获取当月最后一天函数分享
2015/02/02 PHP
PHP7.0版本备注
2015/07/23 PHP
php字符串操作常见问题小结
2016/10/11 PHP
使用jQuery内容过滤选择器选择元素实例讲解
2013/04/18 Javascript
JavaScript字符串插入、删除、替换函数使用示例
2013/07/25 Javascript
JS判断变量是否为空判断是否null
2014/07/25 Javascript
IE中getElementsByName()对有些元素无效的解决方案
2014/09/28 Javascript
js实现获取当前时间是本月第几周的方法
2015/08/11 Javascript
jQuery中iframe的操作(点击按钮新增窗口)
2016/04/20 Javascript
Ext JS框架中日期函数的用法及日期选择控件的实现
2016/05/21 Javascript
Vue.js路由组件vue-router使用方法详解
2016/12/02 Javascript
JavaScript中this的用法及this在不同应用场景的作用解析
2017/04/13 Javascript
js中Function引用类型常见有用的方法和属性详解
2019/12/11 Javascript
vue实现输入一位数字转汉字功能
2019/12/13 Javascript
Vue.js仿Select下拉框效果
2020/02/18 Javascript
vue使用map代替Aarry数组循环遍历的方法
2020/04/30 Javascript
Python3实现爬虫爬取赶集网列表功能【基于request和BeautifulSoup模块】
2018/12/05 Python
详解Python下载图片并保存本地的两种方式
2019/05/15 Python
使用tensorboard可视化loss和acc的实例
2020/01/21 Python
Pycharm中配置远程Docker运行环境的教程图解
2020/06/11 Python
L’Artisan Parfumeur官网:法国香水品牌
2020/08/11 全球购物
个人简历中的自我评价范例
2013/10/29 职场文书
办公室文员工作职责
2014/01/31 职场文书
中文专业学生自我评价范文
2014/02/06 职场文书
乐观自信演讲稿范文
2014/05/21 职场文书
员工教育培训协议书
2014/09/27 职场文书
赔偿协议书
2015/01/27 职场文书
工作失职自我检讨书
2015/05/05 职场文书
redis sentinel监控高可用集群实现的配置步骤
2022/04/01 Redis
Linux中一对多配置日志服务器的详细步骤
2022/07/23 Servers