首页 >后端开发 >php教程 >一个FTP树状目录(PHP)_PHP

一个FTP树状目录(PHP)_PHP

WBOY
WBOY原创
2016-06-01 12:28:211027浏览

结合js做的,具体的话相应要做修改,比如目录制
[HTML]


function hsort($a)
  {
    $b='';
    $c='';
    for($i=0;$i      {
        $j=substr($a[$i],0,1);
        if($ j=='d')
          if($i==0)
            $b=$a[$i];
          else
            $b.='&&%%'.$a [$i];
        else
          if($i==0)
            $c=$a[$i];
          else
            $c.='&&%%'。 $a[$i];
      }
    if($b=='')
      {
        $ff=explode('&&%%',$c);
        return $ ff;
      }
    else
      {
        if($c=='')
          {
            $ff=爆炸('&&%%',$b);
            return $ff;
          }
        else
          {
            $f1=$b.'&&%%'.$c;
            $ff=爆炸('& &%%',$ f1);
            return $ff;
          }
      }
  }
require("./class/ftp.php");
$HOST='localhost';
$USER='huyang';
$PASS='huyang';
function ftpurl($url,$konge,$in,$name)
  {
    if($konge>10)
      {}
    else
      {
        全局 $HOST,$USER,$PASS;
        $ftp=new ftp;
        $ftp->init($HOST,$USER ,$PASS);
        $ftp->initpwd($url);
        $a=$ftp->mulu();
        $ftp->close();
        $ a=hsort($a);
        if($in!=1)
          {
            $sss=$name.'子';
            echo'

';
          }
        $v=0;
        for($i=1;$i {
            $aa=explode(' ',$a[$i]);
            $j=substr($aa[0],0,1);
            if($j=='t ')
              {}
elseif($j=='d')
{
$c=count($aa);
$c-=1;
if(($aa[$c]=='.')||($aa[$c]=='..'))
{}
else
{
$v++;
if($in==1)
{
$name1='URL'.$v.'Parent';
$names='URL'.$v;
echo'
';
                        echo' echo'); return false" >'.$aa[$c].'

                             ';
                      }
                    else
                      {
                        $names=$name.'_'.$v;
                        echo' echo'); return false" >';
                        for($hu=0;$hu<$konge;$hu++)
echo'';
                        echo''.$aa[$c].'


                             ';
                      }
                    $url1=$url.'/'.$aa[$c];//may be need to change
                    $konge1=$konge+1;
                    ftpurl($url1,$konge1,0,$names);
                  }
              }
            else
              {
                $c=count($aa);
                $c-=1;
                if($in==1)
                  {
                    $name='URL'.$i.'Parent';
                    $name1='URL'.$i;
                    echo'
';
                    echo''.$aa[$c].'

                    ';
                 }
               其他
                  {
                    echo'';
                    for($hu=0;$hu                    echo'';
                     echo'一个FTP树状目录(PHP)_PHP'.$aa[$c].'


                   ';
                 }
              }
          }
        if($in!=1)
          echo'';
      }
  }
$ftp=new ftp;
$ftp->init($HOST,$USER,$PASS);
$s=$ftp->pwd();
$ftp->close();
ftpurl($s,0,1,'URL1'); //$s 可能需要更改
?>
[/HTML]
以下为类文件
[HTML]

class ftp
  {
    var $id,$tid,$HOST,$USER,$PASS,$pwd;
    var $china_mulu;
    function init($HOST,$USER,$PASS)
      {
        $this->HOST=$HOST;
        $this->USER=$USER;
        $this->PASS=$PASS;
        $this->setup();
      }
    函数 setup()
      {
        if($this->HOST=='')$this->HOST='localhost';
        if($this-> ;USER=='')$this->USER='';
        if($this->PASS=='')$this->PASS='';
        $this-> ;id=ftp_connect($this->HOST) 或 $this->ftp_msg("无法连接 ftp");
        $this->tid=ftp_login($this->id,$this- >USER,$this->PASS) 或 $this->ftp_msg("打不开");
      }
    function pwd()//访问路径
      {
        $ this->pwd=ftp_pwd($this->id);
        return $this->pwd;
      }
    function initpwd($pwd)
      {
        $this- >pwd=$pwd;
      }
    function mulu()//获取目录
      {
        if(!$this->pwd)
          $this->pwd=ftp_pwd ($this->id);
        $this->chinamulu=ftp_rawlist($this->id,$this->pwd);
        return $this->chinamulu;
}
    function upmulu()//返回上级目录
      {
        $a=ftp_cdup($this->id) or $this->ftp_msg("已经是最uppest了!!");
      }
    function close()
      {
        ftp_quit($this->id);
      }
    function ftp_msg($err)
      {
        打印” <字体颜色=红色>

$err

";
      }
  }
?>
[/HTML]

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn