当前位置:Linux教程 - Php - 自动浏览

自动浏览


(原创)自动浏览

保存为auto.php


  Code: [Copy to clipboard]   
<?
$root_dir
="mid";
$hidden=1;

$h[]="(\.php$)";

?>
<style type="text/css">
span.dir{font-size:14px;font-family:wingdings}
span.file{font-size:18px;font-family:wingdings}
body{font-size:14px;}
.show{text-decoration:under-line}
.hidden{text-decoration:none;color=#cccccc}
</style>
<body background="watermark.gif" bgcolor="#ffffff" text="#000000">
<?
   
function  auto($dir)
{    global
$hidden;
      global
$h;
//凡是配置变量,当在函数中使用的时候,都注意考虑用global!
     
$id=opendir($dir);   
     while(
$fn=readdir($id))
     {    
          if(
$hidden)
           {

            if(
ereg($h[0],$fn)) continue;
                }
          if(
$fn!=".")
       {
        if(
$fn=="..")
           {
         echo
"        <a href=auto.php>最初位置</a>        <a href='#' onclick='history.go(-1)'><!--返回--></a>\n<hr SIZE=1>";
        
/*if($top)
         echo "类型        大小        最新访问                <b>已达最上层</b>\n";          
        else*/
         
echo "类型        大小                最新访问                <a href=auto.php?dir=$dir/..><b>上级目录</b></a>\n";  
}
        else
        {
          
$at=fileatime("$dir/$fn");
          
$at=date("Y-m-d",$at);
          if(
is_dir("$dir/$fn"))
          echo
"<span class=dir>0</span>        ---                $at        <a href=auto.php?dir=$dir/$fn><b>$fn</b></a>\n";  
          else
           {  
$size=filesize("$dir/$fn");
                
//$ts=$size;
                
if($size<1024)
                
$size.="b";
                else if(
$size<1024*1024)
                
$size=(int)($size/1024)."kb";      
                else
                
$size=(int)($size/(1024*1024))."M";  
                
//$size.="$ts";                 
          
echo "<span class=file>2</span>        $size                $at        <a href=go.php?u=$dir/$fn target=_blank>$fn</a>\n";  
           }
         }           
       }  
     }  
    
closedir($id);   
}
?>
<pre>

<?
echo "<h3>".($root_dir)."目录~</h3>";

if(isset(
$dir))
{
$dir=trim($dir);
$baselen=strlen(realpath($root_dir));
$pathlen=strlen(realpath($dir));
        if(
$pathlen>=$baselen)
        {

        
auto($dir);
        }
        else
        {
        
auto($root_dir);

        }

}
else
{
auto($root_dir);

}
?>
<hr SIZE=1>
</pre>
<a target=_blank href=http://haoqi.512j.com class="hidden" onmouseout="this.className='hidden'" onmouseover="this.className='show'">power by haoqi</a>

auto.php
的第一行.如下:
$root_dir="mid";
其中的$root_dir表示你要对外公布的文件夹(我公布的是mid文件夹).
把它改成你想公布的文件夹就可以了.