discuz! 5.0.0 Forum Program to add a section of JS code, let members click to download the attachment before the Automatic pop-up prompt window _php tips

Source: Internet
Author: User
You need to modify the attachment.php file in the root directory
In $attachexists = $ispaid = FALSE;
if (!empty ($checktwo)) {
Add before the end of the?>
} else {
echo "<script>alert (' write the content you want to hint ') </script>";
echo "<meta http-equiv=\" refresh\ "content=\" 0; url= $PHP _self?checktwo=1&aid= $aid \ ">";
}
I set up discuz! on this machine. 5.0.1 Debugging passed the
The complete code is as follows:
<?php
/*
[discuz!] (C) 2001-2006 Comsenz Inc.
This isn't 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}pos TS 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& gt;= ' 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 \ ">";
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.