免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2124 | 回复: 2
打印 上一主题 下一主题

递归树型目录,并能判断倒数第二层及第三层目录 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-06-19 17:31 |只看该作者 |倒序浏览
用递归调用写的数状目录,并能判断倒数第二层及第三层目录

<?php

function sub_string($dir_acc,$acc){
$length_dir=strlen($dir_acc);
$length_acc=strlen($acc);
if(($dir_acc==substr($acc,0,$length_dir))||($acc==substr($dir_acc,0,$length_acc)))
     $res=1;
else $res=0;
return $res;
}

function expland_dir_admin($directory,&$cou_int)
{
       
if ($handle = opendir($directory)) {
         $i=0;
         
     while (($file = readdir($handle)) !== false)
       if (($file != "." && $file != ".."&&(is_dir($directory."/".$file))) $i=$i+1;
           rewinddir($handle);
        if($i>;0){
                $cou=(string)$cou_int;
                print("<tr>;<td width ='10%'>;</td>;<td width='90%' id='brd$cou' style='Display:none;'>;";
                print("<table border='0' cellpadding='0' cellspacing='0'>;";      
                while (($file = readdir($handle)) !== false){
           if (($file != "." && $file != ".."&&(is_dir($directory."/".$file))){
                     if(check_child($directory."/".$file)>;0){
                          $cou_int=$cou_int+1;
                          $cou=(string)$cou_int;
                          if(is_shebei($directory."/".$file)==0)                                 
                 {if($file!=="temp"print("<tr>;<td colspan='3' width='600'  >;&amp;&amp;&amp;&amp;&amp;<img src='image/plus.gif' id='img$cou' style='cursor:hand;'language='javascript' onMouseUp='openbrd2(brd$cou,img$cou,simg$cou);'>;&amp;<label style='cursor:hand;' title='双击弹出功能菜单' onDblClick='showmenuie52(\"$directory/$file\",del_shebei,mon_shebei,alter_shebei,move_shebei,refresh_s)'>;<img src='image/mmc.jpg' id='simg$cou' width='18' height='18' border='0' style='cursor:hand;'>;$file\n</label>;</td>;</tr>;";}
                 else {if($file!=="temp" print("<tr>;<td colspan='3' width='600'>;&amp;&amp;&amp;&amp;&amp;<img src='image/plus.gif' id='img$cou' style='cursor:hand;'language='javascript' onMouseUp='openbrd(brd$cou,img$cou,dirimg$cou);'>;&amp;<label style='cursor:hand;' title='双击弹出功能菜单' onDblClick='showmenuie5(\"$directory/$file\",add_node_p,add_node_c,del_node,alter_node,move_node,add_shebei,refresh_p)'>;<img src='image/dir.gif' id='dirimg$cou' width='18' height='16' border='0' style='cursor:hand;'>;$file\n</label>;</td>;</tr>;";}

                         expland_dir_admin($directory."/".$file,$cou_int);
                         
                         }else {
                                         $sta_dir=$directory."/".$file;
                                
                                        if($file!=="temp"
                                        print("<tr>;<td colspan='3' width='600'>;&amp;&amp;&amp;&amp;&amp;<img src='image/shebei1.bmp' width='16' height='12'>;<a href='displayframe.php?id=$sta_dir' target='mainFrame'>;$file</a>;</td>;</tr>;";
                                        }
                         
                   };
                };
                print("</table>;");
                print("</td>;</tr>;");
         };closedir($handle);
        };
       
       
}


function expland_dir($directory,&$cou_int,$acc_array)
{
       
if ($handle = opendir($directory)) {
         $i=0;
         
     while (($file = readdir($handle)) !== false)
       if (($file != "." && $file != "..")&&(is_dir($directory."/".$file))) $i=$i+1;
           rewinddir($handle);
        if($i>;0){
                $cou=(string)$cou_int;
                print("<tr>;<td width ='10%'>;</td>;<td width='90%' id='brd$cou' style='Display:none;'>;");
                print("<table border='0' cellpadding='0' cellspacing='0'>;");      
                while (($file = readdir($handle)) !== false){
           if (($file != "." && $file != "..")&&(is_dir($directory."/".$file))){
                  
                     if(check_child($directory."/".$file)>;0){
                            $i=0;
                                $in_acc=0;
                                $acc_count=count($acc_array);
                               
                                  while($i<$acc_count){
                                if(sub_string($directory."/".$file."/",$acc_array[$i])==1){$in_acc=1;break;}
                               
                                $i=$i+1;
                            }
                                if($in_acc==1){
                                $cou_int=$cou_int+1;
                                $cou=(string)$cou_int;
                                if(is_shebei($directory."/".$file)==0)       
                           {if($file!=="temp")print("<tr>;<td colspan='3' width='600' style='cursor:hand;'language='javascript' onMouseUp='openbrd2(brd$cou,img$cou,simg$cou);'>;&amp;&amp;&amp;&amp;&amp;<img src='image/plus.gif' id='img$cou'>;&amp;<img src='image/mmc.jpg' id='simg$cou' width='18' height='18'>;$file\n</td>;</tr>;");}
                        else {if($file!=="temp")print("<tr>;<td colspan='3' width='600' style='cursor:hand;'language='javascript' onMouseUp='openbrd(brd$cou,img$cou,dirimg$cou);'>;&amp;&amp;&amp;&amp;&amp;<img src='image/plus.gif' id='img$cou'>;&amp;<img src='image/dir.gif' id='dirimg$cou' width='18' height='16'>;$file\n</td>;</tr>;");}
                                expland_dir($directory."/".$file,$cou_int,$acc_array);
                                 }
                         }else {
                                         $sta_dir=$directory."/".$file;
                                
                                        if($file!=="temp")
                                        print("<tr>;<td colspan='3' width='600'>;&amp;&amp;&amp;&amp;&amp;<img src='image/shebei1.bmp' width='16' height='12'>;<a href='displayframe.php?id=$sta_dir' target='mainFrame'>;$file</a>;</td>;</tr>;");
                                        }
                         
                   };
                };
                print("</table>;");
                print("</td>;</tr>;");
         };closedir($handle);
        };       
}

function check_child($directory)
{
        if ($handle = opendir($directory)) {
         $k=0;
     while (($file = readdir($handle)) !== false)
       if (($file != "." && $file != "..")&&(is_dir($directory."/".$file))) $k=$k+1;
        }
        closedir($handle);
        return $k;
}

function is_shebei($directory)
{
        $is=0;
        if ($handle = opendir($directory)) {
     while (($file = readdir($handle)) !== false)
       if (($file != "." && $file != "..")&&(is_dir($directory."/".$file))) {
                           if(check_child($directory."/".$file)>;0)$is=$is+1;
           }
        }
        closedir($handle);
        return $is;
}

print("<hr size='1' color='#5288c8'>;");
print("<font color='#11498e' size='2' face='Verdana'>;当前登陆用户:</font>;<font face='Verdana' color='#663333' size='2'>;$u</font>;");
print("<hr size='1' color='#5288c8'>;");
$maindir=$_SESSION['main_dir'];
$count_int=0;
if($u=="admin"){
print("<table border='0'width='100%' height='60' cellpadding='0' cellspacing='0' bordercolor='#5288c8' bordercolorlight='#5288c8' bordercolordark='#5288c8'>;");
print("<tr>;<td valign='top'>;");
print("<table border='0' cellpadding='0' cellspacing='0'>;");


if ($dir = @opendir($maindir)) {
  
  while (($file = readdir($dir)) !== false) {
   if (($file != "." && $file != "..")&&(is_dir($maindir."/".$file))){
          if(check_child($maindir."/".$file)>;0){
          $count_int=$count_int+1;
          $count=(string)$count_int;
          if(is_shebei($maindir."/".$file)==0)
      {if($file!=="temp")print("<tr>;<td id='$maindir/$file'  bgcolor='#f7f7ef' colspan='4' width='600' >;<img src='image/plus.gif' id='img$count' style='cursor:hand;'language='javascript' onMouseUp='openbrd2(brd$count,img$count,simg$count);'>;&amp;<label style='cursor:hand;' onDblClick='showmenuie52(\"$maindir/$file\",del_shebei,mon_shebei,alter_shebei,move_shebei,refresh_s)' title='双击弹出功能菜单'>;<img src='image/mmc.jpg' id='simg$count' height='18' width='18' border='0' style='cursor:hand;'>;$file\n</label>;</td>;</tr>;");}
      else {if($file!=="temp")print("<tr>;<td '$maindir/$file'  bgcolor='#f7f7ef' colspan='4' width='600' >;<img src='image/plus.gif' id='img$count' style='cursor:hand;'language='javascript' onMouseUp='openhome(brd$count,img$count);'>;&amp;<label style='cursor:hand;' onDblClick='showmenuie5(\"$maindir/$file\",add_node_p,add_node_c,del_node,alter_node,move_node,add_shebei,refresh_p)' title='双击弹出功能菜单'>;<img src='image/Home.gif' id='dirimg$count' height='18' width='18'  border='0' style='cursor:hand;'>;$file\n</label>;</td>;</tr>;");}
          expland_dir_admin($maindir."/".$file,$count_int);
          
      }else {print("<tr >;<td colspan='4' width='600'>;<a href='displayframe.php?id=$maindir$file' target='mainFrame'>;$file\n</a>;</td>;</tr>;");}
      }
  }  

  closedir($dir);
}
print("</td>;</tr>;</table>;</table>;<br>;");
$user_url="\"manager.php\"";
print("<hr size='1' color='#5288c8'>;");
print("<table border='0' width='100%' height='30' cellpadding='0' cellspacing='0' bgcolor='#f7f7ef' bordercolor='#5288c8' bordercolorlight='#5288c8' bordercolordark='#5288c8'>;");

print("<tr>;<td valign='middle' align='center' height='25' onMouseOver ='this.style.backgroundColor=\"#d4d0c8\"' onMouseOut ='this.style.backgroundColor=\"#f7f7ef\"'>;<a href='#' onclick='openwin($user_url)'>;用户管理</a>;<br>;</td>;</tr>;");
print("</table>;<hr size='1' color='#5288c8'>;");

}
else
{
$acc_int=0;
$access = mysql_db_query("network2003","select `access` from user_access where uid='$uid'");
while($row = mysql_fetch_array($access)) {
  $acc[$acc_int]=$maindir."/".$row["access"];
  
  $acc_int++;
}
mysql_free_result($access);
mysql_close($db);
if(!isset($acc[0]))$acc[0]="default/";

print("<table border='0'width='100%' height='60' cellpadding='0' cellspacing='0' bordercolor='#5288c8' bordercolorlight='#5288c8' bordercolordark='#5288c8'>;");
print("<tr>;<td valign='top'>;");
print("<table border='0' cellpadding='0' cellspacing='0'>;");


if ($dir = @opendir($maindir)) {
  
  while (($file = readdir($dir)) !== false) {
   if (($file != "." && $file != "..")&&(is_dir($maindir."/".$file))){
          if(check_child($maindir."/".$file)>;0){
                          $k=0;
                        $in_acc=0;
                        $array_count=count($acc);
                       
                          while($k<$array_count){
                                                               
                                if(sub_string($maindir."/".$file."/",$acc[$k])==1){$in_acc=1;break;}
                                $k=$k+1;
                               
                        }
                        if($in_acc==1){
                          
                                  $count_int=$count_int+1;
                                  $count=(string)$count_int;
                                  if(is_shebei($maindir."/".$file)==0)
                                      {if($file!=="temp")print("<tr>;<td bgcolor='#f7f7ef' colspan='4' width='600' style='cursor:hand;'language='javascript' onMouseUp='openbrd2(brd$count,img$count,simg$count);'>;<img src='image/plus.gif' id='img$count'>;&amp;<img src='image/mmc.jpg' id='simg$count' height='18' width='18'>;$file\n</td>;</tr>;");}
                              else {if($file!=="temp")print("<tr>;<td bgcolor='#f7f7ef' colspan='4' width='600' style='cursor:hand;'language='javascript' onMouseUp='openhome(brd$count,img$count);'>;<img src='image/plus.gif' id='img$count'>;&amp;<img src='image/Home.gif' id='dirimg$count' height='18' width='18'>;$file\n</td>;</tr>;");}
                                  expland_dir($maindir."/".$file,$count_int,$acc);
                          }
      }else {print("<tr >;<td colspan='4' width='600' >;<a href='displayframe.php?id=$maindir$file' target='mainFrame'>;$file\n</a>;</td>;</tr>;");}
      }
  }  

  closedir($dir);
}
    print("</td>;</tr>;</table>;</table>;<br>;<hr size='1' color='#5288c8'>;");
        $url_p="\"pass_frame.php\"";
        print("<table border='0' width='100%' height='10' cellpadding='0' cellspacing='0' bgcolor='#f7f7ef' bordercolor='#5288c8' bordercolorlight='#5288c8' bordercolordark='#5288c8'>;");
        print("<tr>;<td valign='middle' align='center' height='25' onMouseOver ='this.style.backgroundColor=\"#d4d0c8\"' onMouseOut ='this.style.backgroundColor=\"#f7f7ef\"'>;<a href='#' onclick='passwd($url_p)'>;修改密码</a>;<br>;</td>;</tr>;");

print("</table>;<hr size='1' color='#5288c8'>;");
}
?>;

论坛徽章:
0
2 [报告]
发表于 2003-06-20 04:29 |只看该作者

递归树型目录,并能判断倒数第二层及第三层目录

这个程序可以支持无限级目录,还是只能3级?

论坛徽章:
0
3 [报告]
发表于 2003-06-20 16:49 |只看该作者

递归树型目录,并能判断倒数第二层及第三层目录

的贵的方法应该都是无线的
程序太长,我懒得看了。有没有简化版?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP