首页 > 开发 > PHP > 正文

PHP 列出所用文件夹下所有文件及文件夹

2024-05-04 22:58:41
字体:
来源:转载
供稿:网友

<?
/************************************
    name: listdir
    author: riyao chen
    version: 0.0.1
    date: 2006-05-16
    license: gpl


//this class is to list all file & directory follow a directory
//parameter:$strdir ,which directory you want list; $del_url,the manage url,


*********************************/
class listdir{

 var $dir;
 var $edit_url="";
 var $del_url="";
 
 var $num = 0;

 function listdir($strdir,$del_url="",$edit_url="")
 {
  $this->dir = $strdir;
  $this->del_url = $del_url;
  $this->edit_url = $edit_url;
  }
 
 function makedir($strdir)
 {
 //global $num;
 if (is_dir($strdir)) {
      if ($dh = @opendir($strdir)) {
          while (($file = readdir($dh)) !== false) {
          
           $newdir = $strdir.$file;
           if($file == "." || $file == "..")
               {
                continue;
               }
              
               $this->num = $this->num + 1;
               print str_repeat("&nbsp;",$this->num);
              
               if(filetype($newdir)=="dir")
               {
                print "<br>";
                print "$file  [目录]<br>/n";
               }
               else
               {
                 
                print "<a href='".$this->del_url."?file=".$newdir."'>edit</a> <a href='".$newdir."'>$file</a>  <br>/n";
    }
               if(is_dir($newdir))
               {
                $this->makedir($newdir."/");
                }
               
               $this->num = $this->num - 1;
          }
         print "<br>";
      closedir($dh);
      }
 }

 }
 
 function showdir()
 {
  $this->makedir($this->dir);
  }
}

/*
exemple

include_once("./class.dir.php");
$dir = new listdir("c:/","http://127.0.0.1/index.php");
$dir->showdir();

*/

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表