不太可靠,由于时间仓促 ,可能存在括号不匹配等问题,请帮助修改,完成之后会重发一遍。
安装方法:
首先到后台,升级数据库,执行以下SQL:
- CREATE TABLE cdb_ftpstoreerror (
- aid Integer(5) NOT NULL AUTO_INCREMENT,
- attachment Varchar(100) NOT NULL,
- dateline Integer(10) NOT NULL,
- PRIMARY KEY (aid)
- );
- CREATE TABLE cdb_ftpbackuperror (
- aid Integer(5) NOT NULL AUTO_INCREMENT,
- attachment Varchar(100) NOT NULL,
- dateline Integer(10) 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、打开 admin/forum.inc.php,找:
- $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(!($ftplist['store']['on'])) {
- $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($ftplist['store'], $attach['attachment']);
-
- if($ftplist['backup']['on']){
-
- del_ftp_attach($ftplist['backup'],$attach['attachment']);
- }
- }
- }
复制代码
4、打开 include/post.func.php,找到:
在上面加上:
- global $ftplist,$fid, $timestamp;
复制代码
再找:
- $target = $attachdir.'/'.stripslashes($attach['attachment']);
复制代码
在下面加上:
- if(!$ftplist['store']['on']) {
复制代码
再找:
- $attacharray[] = $attach;
- }
- } else {
- showmessage('post_attachment_save_error');
- }
复制代码
下面加上:
- } else {
- $attach_fname = substr($filename, 0, 64) . '_' . random(12) . '.' . $extension;
- $ftp_store_hd = ftpconnect($ftplist['store']);
-
- //ftp_cdup($result);
- if($attach_subdir) {
- if(!@ftp_chdir($ftp_store_hd, $attach_subdir)) {
- ftp_mkdir($ftp_store_hd, $attach_subdir);
- ftp_chdir($ftp_store_hd, $attach_subdir);
- }
- $attach_fname0 = $attach_subdir . '/' . $attach_fname;
- } else {
- $attach_fname0 = $attach_fname;
- }
- $db->query("INSERT INTO {$tablepre}ftpstoreerror(attachment, dateline) VALUES('{$attach_fname0}', '{$timestamp}')");
- $teid = $db->insert_id();
- if(@ftp_put($ftp_store_hd, $attach_fname, $attach['tmp_name'], FTP_BINARY)) {
- @ftp_close($ftp_store_hd);
- $db->query("DELETE FROM {$tablepre}ftpstoreerror 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;
- if($ftplist['backup']['on']){
- $ftp_backup_hd=ftpconnect($ftplist['backup']);
- if($attach_subdir) {
- if(!@ftp_chdir($ftp_backup_hd, $attach_subdir)) {
- ftp_mkdir($ftp_backup_hd, $attach_subdir);
- ftp_chdir($ftp_backup_hd, $attach_subdir);
- }
-
- }
- $db->query("INSERT INTO {$tablepre}ftpbackuperror(attachment,dateline) VALUES('{$attach_fname0}','{$timestamp}')");
- $teid=$db->insert_id();
- if(@ftp_put($ftp_backup_hd,$attach_fname,$attach['tmp_name'],FTP_BINARY)){
- @ftp_close($ftp_backup_hd);
- $db->query("DELETE FROM {$tablepre}ftpbackuperror WHERE aid={$teid}");
- }
- }
-
-
- } else {
- showmessage('post_attachment_save_error');
- }
- }
复制代码
5、打开 include/editpost.inc.php,找:
- @unlink($attachdir.'/'.$attach['attachment']);
复制代码
改成:
- if(!$ftplist['store']['on']) {
- @unlink($attachdir.'/'.$attach['attachment']);
- } else {
- del_ftp_attach($ftplist['store'], $attach['attachment']);
- if($ftplist['backup']['on'])
- del_ftp_attach($ftplist['backup'],$attach['attachment']);
- }
复制代码
再找:
@unlink($attachdir.'/'.$attach['attachment']);
改成:
if(!$ftplist['store']['on']) {
@unlink($attachdir.'/'.$attach['attachment']);
} else {
del_ftp_attach($ftplist['store'], $attach['attachment']);
if($ftplist['backup'])
del_ftp_attach($ftplist['backup'],$attach['attachment']);
}
6、打开topicadmin.php,找:
找(共两处):
- @unlink($attachdir.'/'.$attach['attachment']);
复制代码
改成:
- if(!$ftplist['store']['on']) {
- @unlink($attachdir.'/'.$attach['attachment']);
- } else {
- del_ftp_attach($ftplist['store'],$att['attachment']);
- if($ftplist['backup']['on'])
- del_ftp_attach($ftplist['backup'],$att['attachment']);
- }
复制代码
7、打开attachment.php,找:
- if(is_readable($filename) && $attachexists) {
复制代码
在上面添加:
- if(!$ftplist['store']['on']) {
复制代码
再找:
- 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['store']);
- $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['store']['url'].'/'.$attach['attachment']);
- }
- if(!$isimage) {
- updatecredits($discuz_uid, $creditspolicy['getattach'], -1);
- }
- }
复制代码
8、完成。
====================================
付上卸载代码:
- DROP TABLE cdb_ftpstoreerror ;
- DROP TABLE cdb_ftpbackuperror;
复制代码
[ 本帖最后由 plainer13 于 2006-5-12 21:48 编辑 ] |