先谈谈本插件的功能和思路。 释义: 网站服务器,指执行帝国cms代码的服务器,简称服务器。 七牛云服务器,指七牛云对象存储空间,简称七牛云。 本插件实现附件上传到七牛云存储。有以下特点: 后台上传图片的时候,可以选择传到七牛云,或者网站
2.可以添加水印,和缩略图。这些操作时在网站完成的,完成后上传到七牛云。网站不保留。 3.文件删除。无缝对接到帝国后台的,和以前的界面操作一样的。 安装方法: 1. 解压本包到e/extend/下 设置 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 qiniu
elseif($fpath==31)// p目录 qiniu
{
$r['filepath']='d/file/p/';
include(ECMS_PATH.'e/extend/jhcQiniu/config.php');
$r['fileurl']=qiniuhost.'/'.$r['filepath'];
}
elseif($fpath==32)//file目录 qiniu
{
$r['filepath']='d/file/';
include(ECMS_PATH.'e/extend/jhcQiniu/config.php');
$r['fileurl']=qiniuhost.'/'.$r['filepath'];
} 3.2本地上传后的处理 查找 //上传文件 在这个函数的尾部有代码: //FileServer if($public_r['openfileserver']) { $efileftp_fr[]=$r['yname']; } 替换为 //FileServer
if($public_r['openfileserver'] && $_POST['save2qiniu'])
{
$efileftp_fr[]=$r['yname'];
//add by jiuhecai for qiniuyun
if($public_r['fpath']<30)$public_r['fpath']=30+$public_r['fpath'];
$filePath = $r[yname];
include_once(ECMS_PATH.'e/extend/jhcQiniu/qiniuEcms.php');
//$key = trim(str_replace(qiniuhost,'',$r['url']),'/');
$urlr=parse_url($r['url']);
$key = trim($urlr['path'],'/');
$r['url']=qiniuhost.'/'.$key;
if($_POST['getsmall'] || $_POST['getmark'])return $r;
$err=qiniuUpFile($filePath,$key);
if ($err !== null) {
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 qiniuyun
if($public_r['fpath']<30)$public_r['fpath']=30+$public_r['fpath'];
$filePath = $r[yname];
include_once(ECMS_PATH.'e/extend/jhcQiniu/qiniuEcms.php');
//$key = trim(str_replace(qiniuhost,'',$r['url']),'/');
$urlr=parse_url($r['url']);
$key = trim($urlr['path'],'/');
$r['url']=qiniuhost.'/'.$key;
if($_POST['getsmall'] || $_POST['getmark'])return $r;
$err=qiniuUpFile($filePath,$key);
if ($err !== null) {
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;
} 也就是将 if($ecms==1) 修改为 if(1==1) 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
DelFiletext($delfile);
//FileServer
if($public_r['openfileserver'])
{
$efileftp_dr[]=$delfile;
//add by jiuhecai for qiniu
if($r['fpath']==31 or $r['fpath']==32){
include_once(ECMS_PATH.'e/extend/jhcQiniu/DoDelFile.php');
$delfile=$fspath['filepath'].$path.$r['filename'];
qiniuDelFile($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['save2qiniu'])
{
$efileftp_fr[]=$name.$filer['filetype'];
//add by jiuhecai for qiniuyun
$fspath=ReturnFileSavePath($classid);
$key = $fspath['filepath'].$filepath.'/'.$insertfile;
$filePath = $name.$filer['filetype'];
include_once(ECMS_PATH.'e/extend/jhcQiniu/qiniuEcms.php');
$err=qiniuUpFile($filePath,$key);
@unlink($filePath);
if(!$_POST['getmark']){
// 上传原文件 删除原文件
$filePath=str_replace('small','',$filePath);
$key=str_replace('small','',$key);
$err=qiniuUpFile($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 qiniuyun
if($public_r['openfileserver'] && $_POST['save2qiniu']){
$efileftp_fr[]=$name.$filer['filetype'];
//add by jiuhecai for qiniuyun
$key = str_replace(ECMS_PATH,'',$groundImage);
$filePath = $groundImage;
include_once(ECMS_PATH.'e/extend/jhcQiniu/qiniuEcms.php');
$err=qiniuUpFile($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="save2qiniu" type="checkbox" id="save2qiniu" value="1" checked>七牛云存储<?}?> 6. 修改文件 e/admin/ecmseditor/editorpage/TranImg.php 查找:<input name="getmark" type="checkbox" id="getmark" value="1" checked> 在之前插入: <?if($public_r['openfileserver']){?> <input name="save2qiniu" type="checkbox" id="save2qiniu" value="1" checked>七牛云存储<?}?>
|