• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

一个FTP树状目录(PHP)

发布: 2007-7-01 15:06 | 作者: admin | 来源: | 查看: 32次 | 进入软件测试论坛讨论

领测软件测试网

结合js做的,具体的话相应要做修改,比如目录制
[HTML]
<script language="JavaScript">
with (document) {
        write("<STYLE TYPE=@#text/css@#>");
        write(".child ")
        write("</STYLE>");
    }
function initIt(){
        divColl = document.all.tags("DIV");
        for (i=0; i<divColl.length; i++) {
            whichEl = divColl(i);
            if (whichEl.className == "child") whichEl.style.display = "none";
        }

}
function expandIt(el) {

        whichEl = eval(el + "Child");
        if (whichEl.style.display == "none") {
            whichEl.style.display = "block";
        }
        else {
            whichEl.style.display = "none";
        }
    }
onload = initIt;
</script>
<LINK href=../main.css rel=stylesheet type=text/css>
<?
function hsort($a)
  {
    $b=@#@#;
    $c=@#@#;
    for($i=0;$i<count($a);$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=explode(@#&&%%@#,$b);
            return $ff;
          }
        else
          {
            $f1=$b.@#&&%%@#.$c;
            $ff=explode(@#&&%%@#,$f1);
            return $ff;
          }
      }
  }
require("./class/ftp.php");
$HOST=@#localhost@#;
$USER=@#huyang@#;
$PASS=@#huyang@#;
function ftpurl($url,$konge,$in,$name)
  {
    if($konge>10)
      {}
    else
      {
        global $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.@#Child@#;
            echo@#<div id="@#.$sss.@#" class="child">@#;
          }
        $v=0;
        for($i=1;$i<count($a);$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@#<div id="@#.$name1.@#" class="parent">@#;
                        echo@#<a href="#" onClick="expandIt(@#;
                        echo"@#".$names."@#";
                        echo@#); return false" ><img src="img/plus.gif" border=0>@#.$aa[$c].@#</a></div>
                             @#;
                      }
                    else
                      {
                        $names=$name.@#_@#.$v;
                        echo@#<a href="#" onClick="expandIt(@#;
                        echo"@#".$names."@#";
                        echo@#); return false" >@#;
                        for($hu=0;$hu<$konge;$hu++)
                          echo@#<img src="img/spacer.gif"  border=0 alt="">@#;
                        echo@#<img src="img/plus.gif"  border=0>@#.$aa[$c].@#</a><br>
                             @#;
                      }
                    $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@#<div id="@#.$name.@#" class="parent">@#;
                    echo@#<a href="#"><img src="img/open.gif" border=0>@#.$aa[$c].@#</a></div>
                    @#;
                  }
                else
                  {
                    echo@#<a href="#">@#;
                    for($hu=0;$hu<$konge;$hu++)
                    echo@#<img src="img/spacer.gif"  border=0 alt="">@#;
                    echo@#<img src="img/open.gif"  border=0>@#.$aa[$c].@#</a><br>
                    @#;
                  }
              }
          }
        if($in!=1)
          echo@#</div>@#;
      }
  }
$ftp=new ftp;
$ftp->init($HOST,$USER,$PASS);
$s=$ftp->pwd();
$ftp->close();
ftpurl($s,0,1,@#URL1@#); //$s may be need to change
?>
[/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();
      }
    function setup()
      {
        if($this->HOST==@#@#)$this->HOST=@#localhost@#;
        if($this->USER==@#@#)$this->USER=@#@#;
        if($this->PASS==@#@#)$this->PASS=@#@#;
        $this->id=ftp_connect($this->HOST) or $this->ftp_msg("can not connect ftp");
        $this->tid=ftp_login($this->id,$this->USER,$this->PASS) or $this->ftp_msg("can not open it");
      }
    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("already be the uppest!!");
      }
    function close()
      {
        ftp_quit($this->id);
      }
    function ftp_msg($err)
      {
        print"<font color=red><h1><center>$err</center></h1></font>";
      }
  }
?>
[/HTML]

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网