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 相关文章推荐
PHP4之真OO
Oct 09 PHP
php正则校验用户名介绍
Jul 19 PHP
php知道与问问的采集插件代码
Oct 12 PHP
php学习笔记 数组的常用函数
Jun 13 PHP
PHP判断文件是否存在、是否可读、目录是否存在的代码
Oct 03 PHP
PHP多线程之内部多线程实例分析
Mar 09 PHP
php session实现多级目录存放实现代码
Feb 03 PHP
PHP函数shuffle()取数组若干个随机元素的方法分析
Apr 02 PHP
PHP读取Excel类文件
May 15 PHP
PHP简单获取随机数的常用方法小结
Jun 07 PHP
thinkphp分页集成实例
Jul 24 PHP
PHP与Web页面交互操作实例分析
Jun 02 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
PHP中利用substr_replace将指定两位置之间的字符替换为*号
2011/01/27 PHP
PHP rsa加密解密使用方法
2015/04/27 PHP
PHP模板解析类实例
2015/07/09 PHP
thinkPHP框架RBAC实现原理分析
2019/02/01 PHP
Code: write(s,d) 输出连续字符串
2007/08/19 Javascript
IE6图片加载的一个BUG解决方法
2010/07/13 Javascript
jQuery的实现原理的模拟代码 -2 数据部分
2010/08/01 Javascript
Js Jquery创建一个弹出层可加载一个页面
2014/05/08 Javascript
jquery获取选中的文本和值的方法
2014/07/08 Javascript
点击button获取text内容并改变样式的js实现
2014/09/09 Javascript
js用拖动滑块来控制图片大小的方法
2015/02/27 Javascript
JavaScript File API实现文件上传预览
2016/02/02 Javascript
jstree创建无限分级树的方法【基于ajax动态创建子节点】
2016/10/25 Javascript
jQuery源码解读之extend()与工具方法、实例方法详解
2017/03/30 jQuery
react-router4 嵌套路由的使用方法
2017/07/24 Javascript
Angular.js中数组操作的方法教程
2017/07/31 Javascript
自定义PC微信扫码登录样式写法
2017/12/12 Javascript
javascript实现数字配对游戏的实例讲解
2017/12/14 Javascript
JS中的回调函数实例浅析
2018/03/21 Javascript
详解vuex状态管理模式
2018/11/01 Javascript
详解mpvue中使用vant时需要注意的onChange事件的坑
2019/05/16 Javascript
解决python ogr shp字段写入中文乱码的问题
2018/12/31 Python
Python Selenium 之关闭窗口close与quit的方法
2019/02/13 Python
python实现合并两个排序的链表
2019/03/03 Python
flask应用部署到服务器的方法
2019/07/12 Python
详解Pymongo常用查询方法总结
2021/01/29 Python
欧缇丽加拿大官方网站:Caudalie加拿大
2019/07/18 全球购物
Hush Puppies澳大利亚官网:舒适的男女休闲和正装鞋
2019/08/24 全球购物
戴尔新西兰官网:Dell New Zealand
2020/01/07 全球购物
Moda Operandi官网:美国奢侈品电商,海淘秀场T台同款
2020/05/26 全球购物
装修致歉信
2014/01/15 职场文书
校园安全标语
2014/06/07 职场文书
学校标语大全
2014/06/19 职场文书
2014年小学语文工作总结
2014/12/20 职场文书
违规违纪检讨书范文
2015/05/06 职场文书
爱国之歌(8首)
2019/09/29 职场文书