大虾们指教。a.php遍历并显示文件夹,
比如testfolder里面有a,b,c等多个文件夹,a里面又有a1,a2,a3等多个文件夹,a1里面又有a11,a22,a33等多个文件夹,遍历时显示如:
a
b
c
当点击a文件夹时出一个参数到另一个文件b.php(b.php可以同一服务器或者不同服务器),如何a.php显示a1,a2,a3。
b,c同理。

解决方案 »

  1.   

    fscan配合is_dir做判断.代码要自己写!
      

  2.   

    提示下fscan配合is_dir做判断怎么用,本人没用过,谢谢了。
      

  3.   

    手册上有例子
    http://www.php.net/manual/en/function.scandir.php
    http://www.php.net/manual/en/function.is-dir.php
      

  4.   

    array scandir ( string $directory [, int $sorting_order = 0 [, resource $context ]] )Returns an array of files and directories from the directory. 
    返回一个$directory路径下的文件和分支路径的数组。你写个php文件试下就知道了!
      

  5.   


    function my_scandir($dir)   
    {   
        $files=array();   
        if(is_dir($dir))   
         {   
            if($handle=opendir($dir))   
             {   
                while(($file=readdir($handle))!==false)   
                 {   
                    if($file!="." && $file!="..")   
                     {   
                        if(is_dir($dir."/".$file))   
                         {   
                            $files[$file]=my_scandir($dir."/".$file);   
                         }   
                        else  
                         {   
                            $files[]=$dir."/".$file;   
                         }   
                     }   
                 }   
                closedir($handle);   
                return $files;   
             }   
         }   
    }   
    print_r(my_scandir("d:\wamp\www\ZF"));
      

  6.   

    <html>
    <head>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("#trigger").bind("click", function(){
      var v = 'a';
              $.post("jajax.post.php",{'v':v},function(data){
              //window.location.reload();
      $('#trigger').html(data) ;
            });
                });
    }) ;</script>
    </head>
    <body>
    <a href="#" id="trigger">click me</a>
    </body>
    </html>
    <?php
    if(array_key_exists('v',$_POST)){
    echo "V = ".$_POST['v'] ;

    }
    ?>
      

  7.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>traversal folder</title>      
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script src="js/jquery-1.js" type="text/javascript"></script>
    </head>
    <style>
    .trigger{cursor:pointer;}
    li img{vertical-align:middle;}
    </style>
    <body>  
    <div id="title"><span></span></div><div id="warning" style="background: none repeat scroll 0% 0% rgb(188, 112, 112); border-bottom: 1px solid rgb(255, 192, 203); border-top: 1px solid rgb(165, 74, 74); color: rgb(0, 0, 0); font-size: 0.8em; padding: 3px; text-align: center; height:35px;">
    </div><div id="wrapper">
      <ul id="top">
    <?
    //$dir1 = $_SERVER["DOCUMENT_ROOT"]."/traversalFolder/testUIFolder/a/index.html<br>";$path = 'testUIFolder';
    function get_filetree_scandir($path){
      $result = array();
      $temp = array();
      if (!is_dir($path)||!is_readable($path)) return null; //检测目录
      $allFiles = scandir($path); //获取目录下所有文件与文件夹
      foreach ($allFiles as $fileName) { //遍历一遍目录下的文件与文件夹
        if (in_array($fileName,array('.','..'))) continue; //无视 . 与 ..
        $fullName = $path.'/'.$fileName; //得到完整文件路径
    $fullNameUrlIHTML = $path.'/'.$fileName.'/index.html'; //得到完整文件路径
    $fullNameUrlSHTML = $path.'/'.$fileName.'/Setup.html'; //得到完整文件路径
    $fullNameUrlIHTM = $path.'/'.$fileName.'/index.htm'; //得到完整文件路径
    $fullNameUrlSHTM = $path.'/'.$fileName.'/Setup.htm'; //得到完整文件路径
    $link = $_SERVER["REQUEST_URI"];
        $linkAnalysis  = parse_url($link);
        $linkDecomposition = explode('/',$linkAnalysis['path']);
        //echo $linkc[1];
    //echo $fullName."<br>";
    if(!in_array($fullName,array('index.html','index.htm','Setup.html','Setup.htm'))){
      //$url = "http://".$_SERVER['HTTP_HOST']."/".$linkDecomposition[1]."/traversalFolder/".$path."/".$fileName;
          $url = "http://".$_SERVER['HTTP_HOST']."/".$linkDecomposition[1]."/".$path."/".$fileName;
        }else{
      $url = "javascript:void(0)";
    }
    //echo $fullName."<br>";
    if (is_dir($fullName)) { //如果是目录的话继续递归
          if (!file_exists($fullNameUrlIHTML) && !file_exists($fullNameUrlIHTM) && !file_exists($fullNameUrlSHTML) && !file_exists($fullNameUrlSHTM)) {
        echo "<li>\n";
        echo "<a class=\"trigger\"><img src=\"image/directory.png\" border=\"0\">&nbsp;$fileName</a>\n";
      }else{
        echo "<ul style=\"display: block;\" class=\"sub\">&nbsp;&nbsp;&nbsp;&nbsp;";
        echo "<li><a href=\"$url\" class=\"trigger\"><img src=\"image/directory.png\" border=\"0\">&nbsp;$fileName</a></li>\n";
    echo "</ul>\n";
    echo "</li>\n";
      }
      
      /*
      echo "<ul style=\"display: block;\" class=\"sub\">&nbsp;&nbsp;&nbsp;&nbsp;";
      echo "<img src=\"image/directory.png\" border=\"0\">&nbsp;$fileName";
      echo "</ul>\n";
      */
      $result[$fileName] = get_filetree_scandir($fullName); //递归开始

        }else {
      //$url = "http://".$_SERVER['HTTP_HOST']."/traversalFolder/".$path."/".$fileName;
      //echo "<li><a href=\"$url\">".$fileName."</a></li>\n";
          $temp[] = $fileName; //如果是文件,就存入数组
        }
      }  foreach ($temp as $tmp) { //把临时数组的内容存入保存结果的数组
        $result[] = $tmp; //这样可以让文件夹排前面,文件在后面
      }
      return $result;
    }print_r(json_encode(get_filetree_scandir($path)));?>  </ul>
    </div>
            
            
    <script type="text/javascript">
    $(function() {
      $('.sub').hide();
        $('.trigger').click( function() {
          $(this).next('.sub').slideToggle();
        });
    });
    </script></body>
    </html>