|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
第一步,下载附件到e\extend目录下
登陆后台后运行/e/extend/ecms_upftp/install按照提示进行安装
安装后的管理地址为/e/extend/ecms_upftp/admin.php
在这里填写对应的FTP信息生成配置文件
第二步,打开e/class/connect.php文件找到以下函数并替换。
- //上传文件
- function DoTranFile($file,$file_name,$file_type,$file_size,$classid,$ecms=0,$deftp=true){
- global $public_r,$class_r,$doetran,$efileftp_fr;
- global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
- //文件类型
- $r[filetype]=GetFiletype($file_name);
- //文件名
- $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
- $r[filename]=$r[insertfile].$r[filetype];
- //日期目录
- $r[filepath]=FormatFilePath($classid,$mynewspath,0);
- $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
- //存放目录
- $fspath=ReturnFileSavePath($classid);
- $r[savepath]=ECMS_PATH.$fspath['filepath'].$filepath;
- //附件地址
- $r[url]=$fspath['fileurl'].$filepath.$r[filename];
- //缩图文件
- $r[name]=$r[savepath]."small".$r[insertfile];
- //附件文件
- $r[yname]=$r[savepath].$r[filename];
- $r[tran]=1;
- //验证类型
- if(CheckSaveTranFiletype($r[filetype]))
- {
- if($doetran)
- {
- $r[tran]=0;
- return $r;
- }
- else
- {
- printerror('TranFail','',$ecms);
- }
- }
- if ($ftpoff && $deftp) {
- $ftp =& new ftps();
- $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
- // 远程存放地址
- $remote = $ftpuppat . str_replace(ECMS_PATH, "", $r[yname]);
- if ($ftp->put($remote, $file)) {
- //为false时,继续上传到网站附件目录,为true时,只上传到FTP上
- if(!$ftpuptb){
- return $r;
- }
- } else {
- printerror2("FTP上传失败!","");
- }
- }
- //上传文件
- $cp=@move_uploaded_file($file,$r[yname]);
- if(empty($cp))
- {
- if($doetran)
- {
- $r[tran]=0;
- return $r;
- }
- else
- {
- printerror('TranFail','',$ecms);
- }
- }
- DoChmodFile($r[yname]);
- $r[filesize]=(int)$file_size;
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_fr[]=$r['yname'];
- }
- return $r;
- }
复制代码
- //远程保存
- function DoTranUrl($url,$classid,$deftp=true){
- global $public_r,$class_r,$ecms_config,$efileftp_fr;
- global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
- //处理地址
- $url=trim($url);
- $url=str_replace(" ","%20",$url);
- $r[tran]=1;
- //附件地址
- $r[url]=$url;
- //文件类型
- $r[filetype]=GetFiletype($url);
- if(CheckSaveTranFiletype($r[filetype]))
- {
- $r[tran]=0;
- return $r;
- }
- //是否已上传的文件
- $havetr=CheckNotSaveUrl($url);
- if($havetr)
- {
- $r[tran]=0;
- return $r;
- }
- //是否地址
- if(!strstr($url,'://'))
- {
- $r[tran]=0;
- return $r;
- }
- $string=ReadFiletext($url);
- if(empty($string))//读取不了
- {
- $r[tran]=0;
- return $r;
- }
- //文件名
- $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
- $r[filename]=$r[insertfile].$r[filetype];
- //日期目录
- $r[filepath]=FormatFilePath($classid,$mynewspath,0);
- $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
- //存放目录
- $fspath=ReturnFileSavePath($classid);
- $r[savepath]=ECMS_PATH.$fspath['filepath'].$filepath;
- //附件地址
- $r[url]=$fspath['fileurl'].$filepath.$r[filename];
- //缩图文件
- $r[name]=$r[savepath]."small".$r[insertfile];
- //附件文件
- $r[yname]=$r[savepath].$r[filename];
- WriteFiletext_n($r[yname],$string);
- $r[filesize]=@filesize($r[yname]);
- //返回类型
- if(strstr($ecms_config['sets']['tranflashtype'],','.$r[filetype].','))
- {
- $r[type]=2;
- }
- elseif(strstr($ecms_config['sets']['tranpicturetype'],','.$r[filetype].','))
- {
- $r[type]=1;
- }
- elseif(strstr($ecms_config['sets']['mediaplayertype'],','.$r[filetype].',')||strstr($ecms_config['sets']['realplayertype'],','.$r[filetype].','))//多媒体
- {
- $r[type]=3;
- }
- else
- {
- $r[type]=0;
- }
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_fr[]=$r['yname'];
- }
- //FTP上传
- if ($ftpoff && $deftp) {
- $ftp =& new ftps();
- $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
- // 远程存放地址
- $remote = $ftpuppat . str_replace(ECMS_PATH, "", $r[savepath]).$r['filename'];
- if ($ftp->put($remote, $r["yname"])) {
- if(!$ftpuptb){
- DelFiletext($r["yname"]);
- }
- print_r($r);exit;
- return $r;
- } else {
- printerror2("FTP上传失败!","");
- }
- }
- return $r;
- }
复制代码
- //删除附件
- function DoDelFile($r){
- global $class_r,$public_r,$efileftp_dr;
- global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
- $path=$r['path']?$r['path'].'/':$r['path'];
- $fspath=ReturnFileSavePath($r[classid],$r[fpath]);
- $delfile=ECMS_PATH.$fspath['filepath'].$path.$r['filename'];
- if ($ftpoff) {
- $ftp =& new ftps();
- $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
- $ftp->f_delete($ftpuppat.$fspath['filepath'].$path.$r['filename']);
- }
- DelFiletext($delfile);
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_dr[]=$delfile;
- }
- }
复制代码
第三步,打开e/class/functions.php,在 define('InEmpireCMSHfun',TRUE); 下面增加如下代码:
- //引入FTP类
- require_once ECMS_PATH . 'e/extend/ecms_upftp/ftps.class.php';
- //引入配置文件
- require_once ECMS_PATH . 'e/extend/ecms_upftp/setconfig.php';
复制代码
第四步,同样是e/class/functions.php这个文件,找到如下函数并替换:
- //截取图片
- function CopyImg($text,$copyimg,$copyflash,$classid,$qz,$username,$theid,$cjid,$mark,$fstb=1){
- global $empire,$public_r,$cjnewsurl,$navtheid,$dbtbpre;
- global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
- if(empty($text))
- {return "";}
- $fstb=(int)$fstb;
- if($copyimg)
- {
- $text=RepImg($text,$copyflash);
- }
- if($copyflash)
- {$text=RepFlash($text,$copyflash);}
- $exp1="[--copyimg--]";
- $exp2="[/--copyimg--]";
- $r=explode($exp1,$text);
- for($i=1;$i<count($r);$i++)
- {
- $r1=explode($exp2,$r[$i]);
- if(strstr($r1[0],"http://")||strstr($r1[0],"https://"))
- {
- $dourl=$r1[0];
- }
- else
- {
- //是否是本地址
- if(!strstr($r1[0],"/")&&$cjnewsurl)
- {
- $fileqz_r=GetPageurlQz($cjnewsurl);
- $fileqz=$fileqz_r['selfqz'];
- $dourl=$fileqz.$r1[0];
- }
- else
- {
- $dourl=$qz.$r1[0];
- }
- }
- if($mark){
- $return_r=DoTranUrl($dourl,$classid,false);
- }else{
- $return_r=DoTranUrl($dourl,$classid);
- }
- $text=str_replace($exp1.$r1[0].$exp2,$return_r[url],$text);
- if($return_r[tran])
- {
- //记录数据库
- $filetime=date("Y-m-d H:i:s");
- //变量处理
- $return_r[filesize]=(int)$return_r[filesize];
- $classid=(int)$classid;
- $return_r[type]=(int)$return_r[type];
- $theid=(int)$theid;
- $cjid=(int)$cjid;
- eInsertFileTable($return_r[filename],$return_r[filesize],$return_r[filepath],$username,$classid,'[URL]'.$return_r[filename],$return_r[type],$theid,$cjid,$public_r[fpath],0,0,$fstb);
- //加水
- if($mark&&$return_r[type]==1)
- {
- GetMyMarkImg($return_r['yname']);
- if ($ftpoff) {
- $ftp =& new ftps();
- $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
- // 远程存放地址
- $remote = $ftpuppat . str_replace(ECMS_PATH, "", $return_r[savepath]).$return_r['filename'];
- if ($ftp->put($remote, $return_r["yname"])) {
- //删除图片
- if(!$ftpuptb){
- DelFiletext($return_r["yname"]);
- }
- } else {
- printerror2("FTP上传失败!","");
- }
- }
- }
- }
- }
- return $text;
- }
复制代码
以下功能暂未完善,
第五步,打开e/admin/ecmseditor/cropimg/CropImage.php 这个文件,找到 if(!file_exists($big_image_name))把下面一行
- printerror('NotCropImage','history.go(-1)');
复制代码
删除或者前面加2个反斜杠。
第六步,打开e/admin/ecmseditor/cropimg/copyimgfun.php这个文件,全部替换以下代码:
- <?php
- //裁剪图片
- function DoCropImage($add,$userid,$username){
- global $empire,$dbtbpre,$public_r,$class_r,$tranpicturetype,$efileftp_fr,$efileftp_dr;
- global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
- $ftp =& new ftps();
- $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
- //参数处理
- $pic_x=(int)$add['pic_x'];
- $pic_y=(int)$add['pic_y'];
- $pic_w=(int)$add['pic_w'];
- $pic_h=(int)$add['pic_h'];
- $doing=(int)$add['doing'];
- $fileid=(int)$add['fileid'];
- $filepass=(int)$add['filepass'];
- //取得文件地址
- if(empty($fileid))
- {
- printerror('NotCropImage','history.go(-1)');
- }
- $filer=$empire->fetch1("select fileid,path,filename,classid,fpath,no from {$dbtbpre}enewsfile where fileid='$fileid'");
- if(empty($filer['fileid']))
- {
- printerror('NotCropImage','history.go(-1)');
- }
- $path=$filer['path']?$filer['path'].'/':$filer['path'];
- $fspath=ReturnFileSavePath($filer['classid'],$filer['fpath']);
- $big_image_name=$fspath['fileurl'].$path.$filer['filename'];
- $up=DoTranUrlimg($big_image_name,$filer);
- $big_image_name=$up['yname'];
- if(!file_exists($big_image_name))
- {
- printerror('NotCropImage','history.go(-1)');
- }
- $filetype=GetFiletype($filer['filename']);//取得文件类型
- if(!strstr($tranpicturetype,','.$filetype.','))
- {
- printerror('CropImageFiletypeFail','history.go(-1)');
- }
- //目标图片
- $new_datepath=FormatFilePath($filer['classid'],'',0);
- $new_path=$new_datepath?$new_datepath.'/':$new_datepath;
- $new_insertfile=ReturnDoTranFilename($filer['filename'],0);
- $new_fspath=ReturnFileSavePath($filer['classid']);
- $new_savepath=ECMS_PATH.$new_fspath['filepath'].$new_path;
- $new_name=$new_savepath.$new_insertfile;
- //处理图片
- $returnr['file']='';
- $returnr['filetype']='';
- if($temp_img_type = @getimagesize($big_image_name)) {preg_match('/\/([a-z]+)$/i', $temp_img_type[mime], $tpn); $img_type = $tpn[1];}
- else {preg_match('/\.([a-z]+)$/i', $big_image_name, $tpn); $img_type = $tpn[1];}
- $all_type = array(
- "jpg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"),
- "gif" => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif" , "exn"=>".gif"),
- "jpeg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"),
- "png" => array("create"=>"imagecreatefrompng" , "output"=>"imagepng" , "exn"=>".png"),
- "wbmp" => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")
- );
- $func_create = $all_type[$img_type]['create'];
- if(empty($func_create) or !function_exists($func_create))
- {
- printerror('CropImageFiletypeFail','history.go(-1)');
- }
- //输出
- $func_output = $all_type[$img_type]['output'];
- $func_exname = $all_type[$img_type]['exn'];
- if(($func_exname=='.gif'||$func_exname=='.png'||$func_exname=='.wbmp')&&!function_exists($func_output))
- {
- $func_output='imagejpeg';
- $func_exname='.jpg';
- }
- $big_image = $func_create($big_image_name);
- $big_width = imagesx($big_image);
- $big_height = imagesy($big_image);
- if(!$big_width||!$big_height||$big_width<10||$big_height<10)
- {
- printerror('CropImageFilesizeFail','history.go(-1)');
- }
- if(function_exists("imagecopyresampled"))
- {
- $temp_image=imagecreatetruecolor($pic_w,$pic_h);
- imagecopyresampled($temp_image, $big_image, 0, 0, $pic_x, $pic_y, $pic_w, $pic_h, $pic_w, $pic_h);
- }
- else
- {
- $temp_image=imagecreate($pic_w,$pic_h);
- imagecopyresized($temp_image, $big_image, 0, 0, $pic_x, $pic_y, $pic_w, $pic_h, $pic_w, $pic_h);
- }
- $func_output($temp_image, $new_name.$func_exname);
- ImageDestroy($big_image);
- ImageDestroy($temp_image);
- $insert_file=$new_name.$func_exname;
- $insert_filename=$new_insertfile.$func_exname;
- if(file_exists($insert_file))
- {
- //删除原图
- if(!$doing)
- {
- $empire->query("delete from {$dbtbpre}enewsfile where fileid='$fileid'");
- DelFiletext($big_image_name);
- if($ftpoff){
- $ftp->f_delete($ftpuppat.$fspath['filepath'].$path.$filer['filename']);
- }
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_dr[]=$big_image_name;
- }
- }
- //写入数据库
- $no='[CropImg]'.$filer['no'];
- $filesize=filesize($insert_file);
- $filesize=(int)$filesize;
- $classid=(int)$filer['classid'];
- $type=1;
- $filetime=date("Y-m-d H:i:s");
- $sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,fpath) values('$insert_filename','$filesize','$username','$new_datepath','$filetime','$classid','$no','$type','$filepass','$filepass','$public_r[fpath]');");
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_fr[]=$insert_file;
- }
- //FTP上传
- if($ftpoff){
- $remote = $ftpuppat.$fspath['filepath'].$new_datepath."/".$insert_filename;
- $ftp->put($remote, $insert_file);
- if(!$ftpuptb){
- DelFiletext($insert_file);
- }
- }
- }
- echo"<script>opener.ReloadChangeFilePage();window.close();</script>";
- db_close();
- exit();
- }
- //保存远程图片
- function DoTranUrlimg($url,$file=array()){
- $classid = $file['classid'];
- global $public_r,$class_r,$tranpicturetype,$tranflashtype,$mediaplayertype,$realplayertype,$efileftp_fr;
- global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
- //处理地址
- $url=trim($url);
- $url=str_replace(" ","%20",$url);
- $r[tran]=1;
- //附件地址
- $r[url]=$url;
- //文件类型
- $r[filetype]=GetFiletype($url);
- if(CheckSaveTranFiletype($r[filetype]))
- {
- $r[tran]=1;
- return $r;
- }
- $string=ReadFiletext($url);
- if(empty($string))//读取不了
- {
- $r[tran]=3;
- return $r;
- }
- //文件名
- $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
- $r[filename]=$r[insertfile].$r[filetype];
- //日期目录
- $r[filepath]=FormatFilePath($classid,$mynewspath,0);
- $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
- //存放目录
- $fspath=ReturnFileSavePath($classid);
- $r[savepath]=ECMS_PATH.$fspath['filepath'].$filepath;
- //附件地址
- $r[url]=$fspath['fileurl'].$filepath.$r[filename];
- //缩图文件
- $r[name]=$r[savepath]."small".$r[insertfile];
- //附件文件
- $r[yname]=$r[savepath].$r[filename];
- WriteFiletext_n($r[yname],$string);
- $r[filesize]=@filesize($r[yname]);
- //返回类型
- if(strstr($tranflashtype,','.$r[filetype].','))
- {
- $r[type]=2;
- }
- elseif(strstr($tranpicturetype,','.$r[filetype].','))
- {
- $r[type]=1;
- }
- elseif(strstr($mediaplayertype,','.$r[filetype].',')||strstr($realplayertype,','.$r[filetype].','))//多媒体
- {
- $r[type]=3;
- }
- else
- {
- $r[type]=0;
- }
- //FileServer
- if($public_r['openfileserver'])
- {
- $efileftp_fr[]=$r['yname'];
- }
- return $r;
- }
- ?>
复制代码
至此即可,此版本暂未做已上传附件的裁剪处理等
插件演示截图:
帝国CMS远程附件插件(免费版)
附件下载:
远程附件.rar
(10.96 KB, 下载次数: 7, 售价: 300 贡献)
|
|