看很多朋友都需要这个东西,就帮大家把这个插件从2.5F转到4.0了。等下就要走了,就把这个东西作为新年礼物送给大家吧!我会回来的。
原作者不是我,是happy0429,我只是把它转到4.0来并加以修改。后台没有转到,前台的功能应该正常了(感谢lixp帮忙测试),请大家谅解。
安装比较麻烦,而且有风险,请大家仔细一点。
安装方法:
首先到后台,升级数据库,执行以下SQL:- ALTER TABLE cdb_attachments ADD ftp Integer(2) DEFAULT '0' NOT NULL;
复制代码- ALTER TABLE cdb_forums ADD ftp Integer(2) DEFAULT '0' NOT NULL;
复制代码- CREATE TABLE cdb_attacherror (
- aid Integer(5) NOT NULL AUTO_INCREMENT,
- attachment Varchar(100) NOT NULL,
- dateline Integer(10) NOT NULL,
- ftp Integer(2) DEFAULT '0' NOT NULL,
- PRIMARY KEY (aid)
- );
复制代码
1、把 attchftp.php 文件放在论坛根目录,并修改里面的值。
2、打开 common.inc.php,找到:- require_once DISCUZ_ROOT.'./config.inc.php';
复制代码
在上面添加:- require_once DISCUZ_ROOT.'./attchftp.php';
复制代码
3、打开 admincp.lang.php 文件,找:- 'forums_threadtypes_forums' => '关联论坛',
复制代码
在下面添加:- 'forums_edit_ftp' => '附件FTP服务器设置',
- 'forums_edit_ftp_comment' => '请确认FTP服务器能正常工作,否则请使用本地服务器',
复制代码
4、打开 admin/forum.inc.php,找:- foreach($perms as $perm) {
- $num = -1;
复制代码
在上面添加:- if(!$forum['ftp']) {
- $forum['ftpname'] = '本地服务器';
- } else {
- $forum['ftpname'] = $ftplist[$forum['ftp']]['name'];
- }
- $ftpselect = "<select name="ftpnew"><option value={$forum[ftp]}>{$forum[ftpname]}</option>";
- $num = 1;
- foreach ($ftplist as $ftpserver){
- $ftpselect .= "<option value={$ftpserver[number]}>{$ftpserver[name]}</option>";
- }
- $ftpselect .= '<option value=0>本地服务器</option></select>';
复制代码
再找:- showsetting('forums_edit_replycredits', 'replycreditsstatus', $forum['replycredits'], 'radio');
复制代码
在下面添加:- showsetting('forums_edit_ftp', 'ftpnew', '', $ftpselect);
复制代码
再找:
在后面加上:
再找:- $tids = 0;
- $query = $db->query("SELECT tid FROM {$tablepre}threads WHERE attachment>'0' AND fid='$fid'");
- while($thread = $db->fetch_array($query)) {
- $tids .= ','.$thread['tid'];
- }
- if($tids) {
- $query = $db->query("SELECT filename FROM {$tablepre}attachments WHERE tid IN ($tids)");
- while($attach = $db->fetch_array($query)) {
- @unlink($attachdir.'/'.$attach['filename']);
- }
- $db->query("DELETE FROM {$tablepre}attachments WHERE tid IN ($tids)");
- }
复制代码 修改成:- $tids = 0;
- $query = $db->query("SELECT tid FROM {$tablepre}threads WHERE attachment>'0' AND fid='$fid'");
- while($thread = $db->fetch_array($query)) {
- $tids .= ','.$thread['tid'];
- }
- if($tids) {
- if(!$attach['ftp']) {
- $query = $db->query("SELECT filename FROM {$tablepre}attachments WHERE tid IN ($tids)");
- while($attach = $db->fetch_array($query)) {
- @unlink($attachdir.'/'.$attach['filename']);
- }
- $db->query("DELETE FROM {$tablepre}attachments WHERE tid IN ($tids)");
- } else {
- del_ftp_attach($attach['ftp'], $attach['attachment']);
- }
- }
复制代码
5、打开 include/cache.inc.php ,找:- case 'forums':
- $table = 'forums f';
- $cols = 'f.fid, f.type, f.name, f.fup, ff.viewperm, a.uid';
复制代码
在 a.uid 后面加上:
6、打开post.php,找:- require_once DISCUZ_ROOT.'./include/post.func.php';
复制代码
在下面加上:- require DISCUZ_ROOT.'./forumdata/cache/cache_forums.php';
- $ftp = $_DCACHE['forums'][$fid][ftp];
- unset($_DCACHE['forums']);
复制代码
7、打开 include/post.func.php,找到:
在上面加上:- global $ftplist, $ftp, $fid, $timestamp;
复制代码
再找:- $target = $attachdir.'/'.stripslashes($attach['attachment']);
复制代码
在下面加上:
再找:- $attacharray[] = $attach;
- }
- } else {
- showmessage('post_attachment_save_error');
- }
复制代码
下面加上:- } else {
- $attach_fname = substr($filename, 0, 64) . '_' . random(12) . '.' . $extension;
- $result = ftpconnect($ftplist[$ftp]);
- ftp_cdup($result);
- if($attach_subdir) {
- if(!@ftp_chdir($result, $attach_subdir)) {
- ftp_mkdir($result, $attach_subdir);
- ftp_chdir($result, $attach_subdir);
- }
- $attach_fname0 = $attach_subdir . '/' . $attach_fname;
- } else {
- $attach_fname0 = $attach_fname;
- }
- $db->query("INSERT INTO {$tablepre}attacherror(attachment, dateline, ftp) VALUES('{$attach_fname0}', '{$timestamp}', '{$ftp}')");
- $teid = $db->insert_id();
- if(@ftp_put($result, $attach_fname, $attach['tmp_name'], FTP_BINARY)) {
- @ftp_close($result);
- $db->query("DELETE FROM {$tablepre}attacherror WHERE aid={$teid}");
- $attach['filename'] = $attach['name'];
- $attach['filesize'] = $attach['size'];
- $attach['perm'] = $allowsetattachperm ? $attachperm[$key] : 0;
- $attach['description'] = cutstr(dhtmlspecialchars($attachdesc[$key]), 100);
- $attach['attachment'] = $attach_fname0;
- $attacharray[] = $attach;
- } else {
- showmessage('post_attachment_save_error');
- }
- }
复制代码
8、打开 include/editpost.inc.php,找:- @unlink($attachdir.'/'.$attach['attachment']);
复制代码
改成:- if(!$attach['ftp']) {
- @unlink($attachdir.'/'.$attach['attachment']);
- } else {
- del_ftp_attach($attach['ftp'], $attach['attachment']);
- }
复制代码
再找:- $query = $db->query("SELECT pid, attachment FROM {$tablepre}attachments WHERE tid='$tid'");
复制代码
改成:- $query = $db->query("SELECT * FROM {$tablepre}attachments WHERE tid='$tid'");
复制代码
再找:- @unlink($attachdir.'/'.$attach['attachment']);
复制代码
改成:- if(!$att['ftp']) {
- @unlink($attachdir.'/'.$attach['attachment']);
- } else {
- del_ftp_attach($attach['ftp'], $attach['attachment']);
- }
复制代码
再找:- $query = $db->query("SELECT aid, attachment FROM {$tablepre}attachments WHERE aid IN ($deleteaids) AND pid='$pid'");
复制代码
改成:- $query = $db->query("SELECT * FROM {$tablepre}attachments WHERE aid IN ($deleteaids) AND pid='$pid'");
复制代码
9、打开topicadmin.php,找:- $query = $db->query("SELECT attachment FROM {$tablepre}attachments WHERE tid IN ($moderatetids)");
复制代码 在 attachment 后面插入:
再找:- $query = $db->query("SELECT attachment FROM {$tablepre}attachments WHERE pid IN ($pids)");
复制代码
在 attachment 后面插入:找(共两处):- @unlink($attachdir.'/'.$attach['attachment']);
复制代码
改成:- if(!$attach['ftp']) {
- @unlink($attachdir.'/'.$attach['attachment']);
- } else {
- del_ftp_attach($att[ftp],$att['attachment']);
- }
复制代码
10、打开attachment.php,找:- if(is_readable($filename) && $attachexists) {
复制代码
在上面添加:
再找:- } else {
- showmessage('attachment_nonexistence');
- }
复制代码 在下面添加:- } else {
- ob_end_clean();
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
- header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
- header('Cache-Control: private');
- header('Pragma: no-cache');
- header('Content-Encoding: none');
- if(!$download && $isimage) {
- header('Content-Disposition: '.(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? 'inline; ' : 'attachment; ').'filename='.$attach['filename']);
- } else {
- header('Content-Disposition: attachment; filename='.$attach['filename']);
- }
- header('Content-Type: '.$attach['filetype']);
- if($download) {
- $result = ftpconnect($ftplist[$attach[ftp]]);
- $ftp_path = dirname($attach[attachment]);
- $ftp_file = basename($attach[attachment]);
- ftp_chdir($result,$ftp_path);
- $tmpfile = tempnam( getcwd()."/", "temp" );
- if(ftp_get($result, $tmpfile, $ftp_file, FTP_BINARY)){
- ftp_quit($result);
- readfile($tmpfile);
- unlink($tmpfile);
- exit;
- } else {
- showmessage('attachment_nonexistence');
- }
- unlink($tmpfile);
- ftp_quit($result);
- } else {
- readfile($ftplist[$attach[ftp]][url].$attach['attachment']);
- }
- if(!$isimage) {
- updatecredits($discuz_uid, $creditspolicy['getattach'], -1);
- }
- }
复制代码
11、分别打开include目录下的newthread.inc.php、newreply.inc.php以及editpost.inc.php,查找:- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
复制代码
都改成:
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, filename, description, filetype, filesize, attachment, downloads, ftp)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0', '$ftp')");
复制代码
12、完成。
====================================
付上卸载代码:
- ALTER TABLE cdb_attachments DROP ftp;
复制代码- ALTER TABLE cdb_forums DROP ftp;
复制代码- DROP TABLE cdb_attacherror;
复制代码
[ 本帖最后由 魔焰男孩 于 2006-2-2 13:49 编辑 ] |