0. 建立一个目录 e/extend/下,名称为 jhcftp ,其下建立文件ftp.php,内容为:
<?php
//帝国网站管理系统FTP
define('InEmpireCMSFtp',TRUE);
//上传一个文件
function jhcUpile($filePath,$key){
$hfile=basename($key);
$path=dirname($key);
$pr=ReturnFtpInfo($ftpid);
$e=new EmpireCMSFTP();
$e->fconnect($pr[ftphost],$pr[ftpport],$pr[ftpusername],$pr[ftppassword],$pr[ftppath],$pr[ftpssl],$pr[ftppasv],$pr[ftpmode],$pr[ftpouttime]);
$e->ftp_mkdis($pr[ftppath],$path);
//上传文件
$err=$e->fTranFile($hfile,$filePath,0,0);
$e->fExit();
return $err; // 成功则返回一
}
class EmpireCMSFTP{
var $ftpconnectid;
var $ftptranmode;
function wipespecial($str){
return str_replace(rray("\n","\r"),array('',''),$str);
}
//链接
function fconnect($ftphost,$ftpport,$ftpusername,$ftppassword,$ftppath,$ftpssl=0,$pasv=0,$tranmode=0,$timeout=0,$checkftp=0){
$ftphost=$thi->wipespecial($ftphost);
$func=$ftpssl&&function_exists('ftp_ssl_connect')?'ftp_ssl_connect':'ftp_connect';
$this->ftpconnectid=@$func($ftphost,$ftpport,20);
if(!$this->ftpconnectid)
}
if($timeout&&function_exists('ftp_set_option'))
{
@ftp_set_option($this->ftpconnectid,FTP_TIMEOUT_SEC,$timeout);
}
$login=$this->fLogin($ftpusername,$ftppassword);
if(!$login)
{
if($checkftp==1)
{
$this->fExit();
return 'UserFail';
}
echo"The username/password for ftp is error!";
$this->fExit();
exit();
}
if($pasv)
{
$this->fPasv(TRUE);
}
$ftppath=empty($ftppath)?'/':$ftppath;
$chdir=$this->fChdr($ftppath);
if(!$chdir)
{
if($checkftp==1)
{
$this->fExit();
return 'PathFail';
}
echo"The path for ftp is error!";
$this->fExit();
exit();
}
$this->ftptranmode=$tranmode?FTP_ASCII:FTP_BINARY;
}
//登录
function fLogin($username,$password) {
$username=$this->wipespecial($username);
$password=$this->wipespecial($password);
return @ftp_login($this->ftpconnectid,$username,$password);
}
//关闭ftp
function fExit(){
return @ftp_quit($this->ftpconnectid);
}
//链接模式
function fPasv($pasv){
return @ftp_pasv($his->ftpconnectid,$pasv);
}
//改变路径
function fChdir($path){
$path=$this->wipespecial($path);
return @ftp_chdir($this->ftpconnectid,$path);
}
//建立目录
function fMkdir($path){
$path=$this->wipespecial($path);
return @ftp_mkdir($this->ftpconnectid,$path);
}
//向服务器发送 SITE 命令
function fSiteCmd($cmd){
$cmd=$this->wipespecial($cmd);
return @ftp_site($this->ftpconnectid,$cmd);
}
//设置目录权限
function fChmoddir($mode,$filename){
$mode=intval($mode);
$filename=$this->wipespecial($filename);
if(function_exists('ftp_chmod'))
{
return @ftp_chmod($this->ftpconnectid,$mode,$filename);
}
else
{
return $this->fSiteCmd('CHMOD '.$mode.' '.$filename);
}
}
//删除目录
function fRmdir($path){
$path=$this->wipespecial($path);
return @ftp_rmdir($this->ftpconnectid,$path);
}
//上传文件
function fTranFile($hfile,$lfile,$startpos=0,$del=0){
$hfile=$this->wipespecial($hfile);
$lfile=$this->wipespecial($lfile);
$startpos=intval($startpos);
$tran=ftp_put($this->ftpconnectid,$hfile,$lfile,$this->ftptranmode,$startpos);
if($del)
{
DelFiletext($lfile);
}
return $tran;
}
//上传单文件(含建目录)
function fTranPathFile($basepath,$path,$hfile,$lfile,$del=0){
//建目录
$this->ftp_mkdirs($basepath,$path);
//上传文件
$this->fTranFile($hfile,$lfile,0,$del);
}
//上传多文件
function fMoreTranFile($hfile,$lfile,$del=0){
$count=count($hfile);
for($i=0;$i<$count;$i++)
{
$this->fTranFile($hfile[$i],$lfile[$i],0,$del);
}
}
//上传多文件(含建目录)
function fMoreTranPathFile($basepath,$path,$hfile,$lfile,$del=0){
//建目录
$this->ftp_mkdirs($basepath,$path);
//上传文件
$this->fMoreTranFile($hfile,$lfile,$del);
}
//下载文件
function fGetFile($lfile,$hfile,$resumepos=0){
$hfile=$this->wipespecial($hfile);
$lfile=$this->wipespecial($lfile);
$resumepos=intval($resumepos);
return @ftp_get($this->ftpconnectid,$lfile,$hfile,$this->ftptranmode,$resumepos);
}
//文件大小
function fSize($hfile){
$hfile=$this->wipespecial($hfile);
return @ftp_size($this->ftpconnectid,$hfile);
}
//删除文件
function fDelFile($hfile){
$hfile=$this->wipespecial($hfile);
return @ftp_delete($this->ftpconnectid,$hfile);
}
//删除多文件
function fMoreDelFile($hfile){
$count=count($hfile);
for($i=0;$i<$count;$i++)
{
$this->fDelFile($hfile[$i]);
}
}
//重命名文件
function fRename($oldfile,$newfile){
$oldfile=$this->wipespecial($oldfile);
$newfile=$this->wipespecial($newfile);
return @ftp_rename($this->ftpconnectid,$oldfile,$newfile);
//上传目录
function ftp_copy($src_dir,$dst_dir){
$src_dir=$this->wipespecial($src_dir);
$dst_dir=$this->wipespecial($dst_dir);
if(!$this->fChdir($dst_dir))
{
$this->fMkdir($dst_dir);
}
$d=@opendir($src_dir);
while($file=@readdir($d))
{
if($file!= "."&&$file!="..")
{
if(is_dir($src_dir."/".$file))
{
$this->ftp_copy($src_dir."/".$file,$dst_dir."/".$file);
}
else
{
$this->fTranFile($dst_dir."/".$file,$src_dir."/".$file);
}
}
}
@closedir($d);
}
//返回目录的文件列表
function fNlist($path) {
$path=$this->wipespecial($path);
return @ftp_nlist($this->ftpconnectid,$path);
}
//删除目录
function ftp_rmAll($path,$flag=true){
$path=$this->wipespecial($path);
if($flag)
{
$ret=$this->fRmdir($path)||$this->fDelFile($path);
}
else
{
$ret=false;
}
if(!$ret)
{
$files=$this->fNlist($path);
foreach($files as $values)
{
$values=basename($values);
$dirfile=$path.'/'.$values;
if($this->fSize($dirfile)==-1)
{
$this->fDelFile($dirfile);
}
else
{
$this->ftp_rmAll($dirfile,true);
}
}
if($flag)
{
return $this->fRmdir($path);
}
else
{
return true;
}
}
else
{
return $ret;
}
}
//建多目录
function ftp_mkdirs($basepath,$path){
$basepath=$this->wipespecial($basepath);
$path=$this->wipespecial($path);
if(empty($path))
{
return '';
}
$r=explode('/',$path);
$count=count($r);
for($i=0;$i<$count;$i++)
{
if($i>0)
{
$returnpath.='/'.$r[$i];
}
else
{
$returnpath.=$r[$i];
}
$createpath=$basepath.$returnpath;
$mk=$this->fMkdir($createpath);
/*if(!$this->fChdir($createpath))
{
$mk=$this->fMkdir($createpath);
if(empty($mk))
{
// printerror("CreatePathFail","");
}
}*/
}
$this->fChdir($createpath);
}
}
?>
1. 建立扩展变量
ftpdomain
存入缓存,用来保存ftp服务器域名
比如这样的: https://wap.1cn.cc
设置 config.php中的参数为你申请到的。
2. 修改文件 e/admin/SetEnews.php,增加远程附件开关
查找:
<tbody id="setfileserver" style="display:none">
</tbody>
在此前增加:
<tr>
<td height="25" colspan="2" class="header">远程附件设置</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">启用远程附件</td>
<td height="25" bgcolor="#FFFFFF"><input type="radio" name="openfileserver" value="1"<?=$r['openfileserver']==1?' checked':''?> onclick="setfileserver.style.display='';">
是
<input type="radio" name="openfileserver" value="0"<?=$r['openfileserver']==0?' checked':''?> onclick="setfileserver.style.display='none';">
否 </td>
</tr>
3. 修改/e/class/connet.php
3.1查找: //返回附件目录
看到如下代码:
//返回附件目录
function ReturnFileSavePath($classid,$fpath=''){
global $public_r,$class_r;
$fpath=$fpath||strstr(','.$fpath.',',',0,')?$fpath:$public_r['fpath'];
$efileurl=eReturnFileUrl();
if($fpath==1)//p目录
{
$r['filepath']='d/file/p/';
$r['fileurl']=$efileurl.'p/';
}
elseif($fpath==2)//file目录
{
$r['filepath']='d/file/';
$r['fileurl']=$efileurl;
}
在这个后面添加:
//add by jiuhecai for ftp
elseif($fpath==31)// p目录 ftp
{
$r['filepath']='d/file/p/';
$r['fileurl']=$public_r['add_ftpdomain'].'/'.$r['filepath'];
3.2本地上传后的处理
查找 //上传文件
在这个函数的尾部有代码:
//FileServer
if($public_r['openfileserver'])
{
$efileftp_fr[]=$r['yname'];
}
替换为
//FileServer
if($public_r['openfileserver'] && $_POST['save2ftp'])
{
$efileftp_fr[]=$r['yname'];
//add by jiuhecai for ftpyun
if($public_r['fpath']<30)$public_r['fpath']=30+$public_r['fpath'];
$filePath = $r[yname];
include_once(ECMS_PATH.'e/extend/jhcftp/ftp.php');
//$key = trim(str_replace($public_r['add_ftpdomain'],'',$r['url']),'/');
$urlr=parse_url($r['url']);
$key = trim($urlr['path'],'/');
$r['url']=$public_r['add_ftpdomain'].'/'.$key;
if($_POST['getsmall'] || $_POST['getmark'])return $r;
$err=jhcUpFile($filePath,$key);
if (!$err) {
if($doetran)
{
$r[tran]=0;
return $r;
}
else
{
printerror('TranFail','',$ecms);
}
} else {
// 上传成功
}
// 不用了才删除
@unlink($filePath);
}
3.3 远程上传后的处理 查找: //远程保存
在这个函数的尾部有代码:
//FileServer
if($public_r['openfileserver'])
{
$efileftp_fr[]=$r['yname'];
}
这个代码后3.2中的是相同的。替换为:
//FileServer
if($public_r['openfileserver'])
{
$efileftp_fr[]=$r['yname'];
//add by jiuhecai for ftpyun
if($public_r['fpath']<30)$public_r['fpath']=30+$public_r['fpath'];
$filePath = $r[yname];
include_once(ECMS_PATH.'e/extend/jhcftp/ftp.php');
//$key = trim(str_replace($public_r['add_ftpdomain'],'',$r['url']),'/');
$urlr=parse_url($r['url']);
$key = trim($urlr['path'],'/');
$r['url']=$public_r['add_ftpdomain'].'/'.$key;
if($_POST['getsmall'] || $_POST['getmark'])return $r;
$err=jhcUpFile($filePath,$key);
if (!$err) {
if($doetran)
{
$r[tran]=0;
return $r;
}
else
{
printerror('TranFail','',$ecms);
}
} else {
// 上传成功
}
// 不用了才删除
@unlink($filePath);
}
3.4 地址的正确返回 查找 //返回附件域名地址
看到代码:
//返回附件域名地址
function eReturnFileUrl($ecms=0){
global $public_r;
if($ecms==1)
{
return $public_r['fileurl'];
}
$fileurl=$public_r['openfileserver']?$public_r['fs_purl']:$public_r['fileurl'];
return $fileurl;
}
修改为:
//返回附件域名地址
function eReturnFileUrl($ecms=0){
global $public_r;
if(1=1)
{
return $public_r['fileurl'];
}
$fileurl=$public_r['openfileserver']?$public_r['fs_purl']:$public_r['fileurl'];
return $fileurl;
}
3.5 删除附件
查找函数 function DoDelFile:
//删除附件
function DoDelFile($r){
global $class_r,$public_r,$efileftp_dr;
$path=$r['path']?$r['path'].'/':$r['path'];
$fspath=ReturnFileSavePath($r[classid],$r[fpath]);
$delfile=eReturnEcmsMainPortPath().$fspath['filepath'].$path.$r['filename'];//moreport
DelFiletext($delfile);
//FileServer
if($public_r['openfileserver'])
{
$efileftp_dr[]=$delfile;
}
}
修改为
//删除附件
function DoDelFile($r){
global $class_r,$public_r,$efileftp_dr;
$path=$r['path']?$r['path'].'/':$r['path'];
$fspath=ReturnFileSavePath($r[classid],$r[fpath]);
$delfile=eReturnEcmsMainPortPath().$fspath['filepath'].$path.$r['filename'];//moreport
//FileServer
if($public_r['openfileserver'])
{
$efileftp_dr[]=$delfile;
//add by jiuhecai for ftp
if($r['fpath']==31 or $r['fpath']==32){
include_once(ECMS_PATH.'e/extend/jhcftp/ftp.php');
jhcDelFile($delfile);
}
}
}
4. 修改文件/e/class/functions.php
修改三个函数: 生成缩略图 图片加水印
4.1 生成缩略图
在函数
//生成缩略图
function GetMySmallImg
的尾部有代码:
//FileServer
if($public_r['openfileserver'])
{
$efileftp_fr[]=$name.$filer['filetype'];
}
修改为:
//FileServer
if($public_r['openfileserver'] && $_POST['save2ftp'])
{
$efileftp_fr[]=$name.$filer['filetype'];
//add by jiuhecai for ftpyun
$fspath=ReturnFileSavePath($classid);
$key = $fspath['filepath'].$filepath.'/'.$insertfile;
$filePath = $name.$filer['filetype'];
include_once(ECMS_PATH.'e/extend/jhcftp/ftp.php');
$err=jhcUpFile($filePath,$key);
@unlink($filePath);
if(!$_POST['getmark']){
// 上传原文件 删除原文件
$filePath=str_replace('small','',$filePath);
$key=str_replace('small','',$key);
$err=jhcUpFile($filePath,$key);
unlink($filePath);
}else{
}
}
4.2 图片加水印
查找函数(其实和4.1的代码相邻),
//图片加水印
function GetMyMarkImg($groundImage){
global $public_r;
if(empty($groundImage))
{
return "";
}
imageWaterMark($groundImage,$public_r['markpos'],$public_r['markimg'],$public_r['marktext'],$public_r['markfontsize'],$public_r['markfontcolor'],$public_r['markfont'],$public_r['markpct'],$public_r['jpgquality']);
}
修改为:
//图片加水印
function GetMyMarkImg($groundImage){
global $public_r;
if(empty($groundImage))
{
return "";
}
imageWaterMark($groundImage,$public_r['markpos'],$public_r['markimg'],$public_r['marktext'],$public_r['markfontsize'],$public_r['markfontcolor'],$public_r['markfont'],$public_r['markpct'],$public_r['jpgquality']);
//FileServer add by jiuhecai for ftpyun
if($public_r['openfileserver'] && $_POST['save2ftp']){
$efileftp_fr[]=$name.$filer['filetype'];
//add by jiuhecai for ftpyun
$key = str_replace(ECMS_PATH,'',$groundImage);
$filePath = $groundImage;
include_once(ECMS_PATH.'e/extend/jhcftp/ftp.php');
$err=jhcUpFile($filePath,$key);
@unlink($filePath);
}
}
5. 修改文件 e/admin/ecmseditor/file.php
查找:
<input name="getmark" type="checkbox" id="getmark" value="1" checked>
在之前插入:
<?if($public_r['openfileserver']){?> <input name="save2ftp" type="checkbox" id="save2ftp" value="1" checked>ftp存储<?}?>
6. 修改文件 e/admin/ecmseditor/editorpage/TranImg.php
查找:
<input name="getmark" type="checkbox" id="getmark" value="1" checked>
在之前插入:
<?if($public_r['openfileserver']){?> <input name="save2ftp" type="checkbox" id="save2ftp" value="1" checked>ftp存储<?}?>
在线下载列表
评论列表()