用户名:  密码:    
中药方大全小图标
关键字:  
您当前的位置:首页 > 其他 > 网站日记

php的代码片段之FTP操作类

提示: 阅读权限:公开  来源:原创  作者:中药方大全
  1. <?php
  2.  
  3. /**
  4.  * FTP操作类
  5.  * @author chenzhouyu
  6.  *
  7.  * 使用$ftps = pc_base::load_sys_class('ftps');进行初始化。
  8.  * 首先通过 $ftps->connect($host,$username,$password,$post,$pasv,$ssl,$timeout);进行FTP服务器连接。
  9.  * 通过具体的函数进行FTP的操作。
  10.  * $ftps->mkdir() 创建目录,可以创建多级目录以“/abc/def/higk”的形式进行多级目录的创建。
  11.  * $ftps->put()上传文件
  12.  * $ftps->rmdir()删除目录
  13.  * $ftps->f_delete()删除文件
  14.  * $ftps->nlist()列出指定目录的文件
  15.  * $ftps->chdir()变更当前文件夹
  16.  * $ftps->get_error()获取错误信息
  17.  */
  18.  
  19. class ftps {
  20.  
  21.     //FTP 连接资源
  22.     private $link;
  23.     //FTP连接时间
  24.     public $link_time;
  25.     //错误代码
  26.     private $err_code = 0;
  27.     //传送模式{文本模式:FTP_ASCII, 二进制模式:FTP_BINARY}
  28.     public $mode = FTP_BINARY;
  29.  
  30.     /**
  31.      * 连接FTP服务器
  32.      * @param string $host       服务器地址
  33.      * @param string $username   用户名
  34.      * @param string $password   密码
  35.      * @param integer $port       服务器端口,默认值为21
  36.      * @param boolean $pasv        是否开启被动模式
  37.      * @param boolean $ssl      是否使用SSL连接
  38.      * @param integer $timeout     超时时间 
  39.      */
  40.     public function connect($host, $username = '', $password = '', $port = '21', $pasv = false, $ssl = false, $timeout = 30) {
  41.         $start = time();
  42.         if ($ssl) {
  43.             if (!$this->link = @ftp_ssl_connect($host, $port, $timeout)) {
  44.                 $this->err_code = 1;
  45.                 return false;
  46.             }
  47.         } else {
  48.             if (!$this->link = @ftp_connect($host, $port, $timeout)) {
  49.                 $this->err_code = 1;
  50.                 return false;
  51.             }
  52.         }
  53.  
  54.         if (@ftp_login($this->link, $username, $password)) {
  55.             if ($pasv)
  56.                 ftp_pasv($this->link, true);
  57.             $this->link_time = time() - $start;
  58.             return true;
  59.         } else {
  60.             $this->err_code = 1;
  61.             return false;
  62.         }
  63.         register_shutdown_function(array(&$this, 'close'));
  64.     }
  65.  
  66.     /**
  67.      * 创建文件夹
  68.      * @param string $dirname 目录名,
  69.      */
  70.     public function mkdir($dirname) {
  71.         if (!$this->link) {
  72.             $this->err_code = 2;
  73.             return false;
  74.         }
  75.         $dirname = $this->ck_dirname($dirname);
  76.         $nowdir = '/';
  77.         foreach ($dirname as $v) {
  78.             if ($v && !$this->chdir($nowdir . $v)) {
  79.                 if ($nowdir)
  80.                     $this->chdir($nowdir);
  81.                 @ftp_mkdir($this->link, $v);
  82.             }
  83.             if ($v)
  84.                 $nowdir .= $v . '/';
  85.         }
  86.         return true;
  87.     }
  88.  
  89.     /**
  90.      * 上传文件
  91.      * @param string $remote 远程存放地址
  92.      * @param string $local 本地存放地址
  93.      */
  94.     public function put($remote, $local) {
  95.  
  96.         if (!$this->link) {
  97.             $this->err_code = 2;
  98.             return false;
  99.         }
  100.         $dirname = pathinfo($remote, PATHINFO_DIRNAME);
  101.         if (!$this->chdir($dirname)) {
  102.             $this->mkdir($dirname);
  103.         }
  104.         if (@ftp_put($this->link, $remote, $local, $this->mode)) {
  105.             return true;
  106.         } else {
  107.             $this->err_code = 7;
  108.             return false;
  109.         }
  110.     }
  111.  
  112.     /**
  113.      * 删除文件夹
  114.      * @param string $dirname  目录地址
  115.      * @param boolean $enforce 强制删除
  116.      */
  117.     public function rmdir($dirname, $enforce = false) {
  118.         if (!$this->link) {
  119.             $this->err_code = 2;
  120.             return false;
  121.         }
  122.         $list = $this->nlist($dirname);
  123.         if ($list && $enforce) {
  124.             $this->chdir($dirname);
  125.             foreach ($list as $v) {
  126.                 $this->f_delete($v);
  127.             }
  128.         } elseif ($list && !$enforce) {
  129.             $this->err_code = 3;
  130.             return false;
  131.         }
  132.         @ftp_rmdir($this->link, $dirname);
  133.         return true;
  134.     }
  135.  
  136.     /**
  137.      * 删除指定文件
  138.      * @param string $filename 文件名
  139.      */
  140.     public function f_delete($filename) {
  141.         if (!$this->link) {
  142.             $this->err_code = 2;
  143.             return false;
  144.         }
  145.         if (@ftp_delete($this->link, $filename)) {
  146.             return true;
  147.         } else {
  148.             $this->err_code = 4;
  149.             return false;
  150.         }
  151.     }
  152.  
  153.     /**
  154.      * 返回给定目录的文件列表
  155.      * @param string $dirname  目录地址
  156.      * @return array 文件列表数据
  157.      */
  158.     public function nlist($dirname) {
  159.         if (!$this->link) {
  160.             $this->err_code = 2;
  161.             return false;
  162.         }
  163.         if ($list = @ftp_nlist($this->link, $dirname)) {
  164.             return $list;
  165.         } else {
  166.             $this->err_code = 5;
  167.             return false;
  168.         }
  169.     }
  170.  
  171.     /**
  172.      * 在 FTP 服务器上改变当前目录
  173.      * @param string $dirname 修改服务器上当前目录
  174.      */
  175.     public function chdir($dirname) {
  176.         if (!$this->link) {
  177.             $this->err_code = 2;
  178.             return false;
  179.         }
  180.         if (@ftp_chdir($this->link, $dirname)) {
  181.             return true;
  182.         } else {
  183.             $this->err_code = 6;
  184.             return false;
  185.         }
  186.     }
  187.  
  188.     /**
  189.      * 获取错误信息
  190.      */
  191.     public function get_error() {
  192.         if (!$this->err_code)
  193.             return false;
  194.         $err_msg = array(
  195.             '1' => 'Server can not connect',
  196.             '2' => 'Not connect to server',
  197.             '3' => 'Can not delete non-empty folder',
  198.             '4' => 'Can not delete file',
  199.             '5' => 'Can not get file list',
  200.             '6' => 'Can not change the current directory on the server',
  201.             '7' => 'Can not upload files'
  202.         );
  203.         return $err_msg[$this->err_code];
  204.     }
  205.  
  206.     /**
  207.      * 检测目录名
  208.      * @param string $url 目录
  209.      * @return 由 / 分开的返回数组
  210.      */
  211.     private function ck_dirname($url) {
  212.         $url = str_replace('', '/', $url);
  213.         $urls = explode('/', $url);
  214.         return $urls;
  215.     }
  216.  
  217.     /**
  218.      * 关闭FTP连接
  219.      */
  220.     public function close() {
  221.         return @ftp_close($this->link);
  222.     }
  223.  
  224. }

[分享]让你的网站和商业版一样支持附件远程FTP上传 

第一步,下载附件到eextend目录下
修改附件中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=""; %20 %20 %20 %20$exp2="";
        $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,请回复!
tags: php 代码 片段 FTP 操作类
返回顶部
推荐资讯
视频:田纪钧讲关节不痛的秘密、膝关节拉筋法
视频:田纪钧讲关节不
白露到了,你还好吗?
白露到了,你还好吗?
尿疗与断食
尿疗与断食
给风疹反复发作女孩的药方(组图)
给风疹反复发作女孩的
相关文章
栏目更新
栏目热门
  1. libreoffice7的命令大全
  2. 帝国cms代码片段备忘录
  3. 帝国cms插件安装模板
  4. 帝国cms插件之标题生成标题图片
  5. 帝国cms全站搜索的分页格式如何修改-流程
  6. 帝国cms中点卡怎么可以直接用来网站的登录
  7. 帝国cms插件之迅搜
  8. php代码判断是不是微信内部浏览器
  9. useragent两千条,爬虫专用
  10. 帝国cms7.2函数大全