帝国论坛帝国网站管理系统交流区帝国CMS使用交流[分享]让你的网站和商业版一样支持附件远程FTP上传 【本版专题贴子】  
 1/7     1 2 3 4 5 6 7 ›› ›|
主题:[分享]让你的网站和商业版一样支持附件远程FTP上传 [加入收藏夹]   

phome4429
用户头衔:进士

精华贴   :2
发贴数   :554
经验值   :3711
注册时间:2008-11-28
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 1 楼]
[分享]让你的网站和商业版一样支持附件远程FTP上传
第一步,下载附件到e\extend目录下
修改附件中setconfig.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 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;
        }
}





//远程保存
function DoTranUrl($url,$classid,$deftp=true){
        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]=0;
                return $r;
        }
        //是否已上传的文件
        $havetr=CheckNotSaveUrl($url);
        if($havetr)
        {
                $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($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'];
        }
        //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;
}


第三步,打开e/class/functions.php,在“define('InEmpireCMSHfun',TRUE);”下面增加如下代码
//引入FTP类
require_once ECMS_PATH . 'e/extend/upftp/ftps.class.php';
//引入配置文件
require_once ECMS_PATH . 'e/extend/upftp/setconfig.php';

第四步,同样是e/class/functions.php这个文件,找到如下函数并替换


//截取图片
function CopyImg($text,$copyimg,$copyflash,$classid,$qz,$username,$theid,$cjid,$mark){
        global $empire,$public_r,$cjnewsurl,$navtheid,$dbtbpre;
        global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
        if(empty($text))
        {return "";}
        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;
                        $sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,onclick,fpath) values('$return_r[filename]',$return_r[filesize],'$username','$return_r[filepath]','$filetime',$classid,'[URL]".$return_r[filename]."',$return_r[type],$theid,$cjid,0,'$public_r[fpath]');");
                        //加水
                        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;
}
?>


到此结束!我已经在使用了,目前没有发现其他问题,如果有发现BUG,请回复!
首发地址:http://www.abc3210.com/2011/phper_11/109.html

上传以下附件:
[下载 *.rar](文件大小:2.21 KB,下载次数:432)

[该贴被修改 1 次,最后修改时间 2011-11-03 14:49:17 ]


失败注定是真理
**************************
插件问题等请不要加我Q,论坛或我网站提问!
QQ:442981383
插件、风格、问题求助尽在随意
问答、小说、SWFupload、发号抽奖、采集自动审核发布
2011-11-03 14:38:32 已设置保密 顶部 回复 引用 报告 编辑 删除

phome4429
用户头衔:进士

精华贴   :2
发贴数   :554
经验值   :3711
注册时间:2008-11-28
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 2 楼]



上传以下图片:


[该贴被修改 1 次,最后修改时间 2011-11-03 14:42:50 ]


失败注定是真理
**************************
插件问题等请不要加我Q,论坛或我网站提问!
QQ:442981383
插件、风格、问题求助尽在随意
问答、小说、SWFupload、发号抽奖、采集自动审核发布
2011-11-03 14:38:49 已设置保密 顶部 回复 引用 报告 编辑 删除

caisheng
用户头衔:进士

精华贴   :0
发贴数   :652
经验值   :3063
注册时间:2008-10-24
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 3 楼]

     



http://www.henaw.com(和娜网)
2011-11-03 15:26:40 已设置保密 顶部 回复 引用 报告 编辑 删除

fishren
用户头衔:举人

精华贴   :0
发贴数   :374
经验值   :995
注册时间:2008-03-10
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 4 楼]

好用不?




2011-11-03 15:38:25 已设置保密 顶部 回复 引用 报告 编辑 删除

support
用户头衔:秀才

精华贴   :0
发贴数   :68
经验值   :508
注册时间:2011-09-21
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 5 楼]

多谢分享。




2011-11-03 16:49:02 已设置保密 顶部 回复 引用 报告 编辑 删除

8877
用户头衔:进士

精华贴   :0
发贴数   :1195
经验值   :4218
注册时间:2006-06-15
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 6 楼]

楼主好人!




2011-11-03 20:52:52 已设置保密 顶部 回复 引用 报告 编辑 删除

pingpong
用户头衔:探花

精华贴   :0
发贴数   :9328
经验值   :24281
注册时间:2008-11-02
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 7 楼]

看着比较复杂,但要支持的




2011-11-04 08:07:51 已设置保密 顶部 回复 引用 报告 编辑 删除

likeni1314
用户头衔:秀才

精华贴   :0
发贴数   :68
经验值   :566
注册时间:2009-06-16
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 8 楼]

不错!支持水兄!




2011-11-04 09:23:01 已设置保密 顶部 回复 引用 报告 编辑 删除

un1x
用户头衔:秀才

精华贴   :0
发贴数   :70
经验值   :405
注册时间:2010-08-10
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 9 楼]

这个可以有
感谢分享!




2011-11-05 08:36:40 已设置保密 顶部 回复 引用 报告 编辑 删除

贝卡蓝依
用户头衔:举人

精华贴   :0
发贴数   :326
经验值   :1096
注册时间:2006-07-21
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 10 楼]

得顶下!!



专业网站建设。仿站。做模板。页面设计。各种代码问题解决。采集规则。老会员性欲保证。QQ8875-096========
帝国爱好者交流群 48024477
2011-11-05 09:42:01 已设置保密 顶部 回复 引用 报告 编辑 删除
 1/7     1 2 3 4 5 6 7 ›› ›|

快速回复
内容

表情
使用EBB代码 使用smile代码 显示签名 自动分析url 自动分析img
     【进入高级模式】   (按 Ctrl+Enter 直接提交)
    顶部  加入收藏夹
关于帝国 | 广告服务 | 联系我们 | 法律声明 | 隐私条款 | 许可协议
Powered by: EBB Version 2.2.1