php专区

 首页 > php专区 > PHP高级 > 文件上传 > PHP 读取目录,删除 - php文件操作

PHP 读取目录,删除 - php文件操作

分享到:
【字体:
导读:
          本文章提供一款php目录管理程序,他可以对目录下的文件,文件夹,等各种文件进行管理删除操作,可以支持无限级目录的管理,代码如下:?phpinclude(class.php);$path=$_get[#39;path#39;];if($path==......

PHP 读取目录,删除

本文章提供一款php目录管理程序,他可以对目录下的文件,文件夹,等各种文件进行管理删除操作,可以支持无限级目录的管理,代码如下:

  1. include("class.php"); 
  2. $path = $_get['path']; 
  3. if($path == ""){ 
  4.  $path = "dir";  
  5. }else
  6.  if(!strstr($path,"dir")){ 
  7.   $path = "dir/".$path
  8.  }else
  9.   $path = $path;  
  10.  } 
  11.  
  12. $newdir = new dirver(); 
  13. $newdir -> setpath($path); 
  14. $newdir -> dirdata(); 
  15. $files = $newdir -> getfiles(); 
  16. $dirs = $newdir -> getdirs(); 
  17. //print_r($files); 
  18. //print_r($dirs); 
  19.  
  20. echo(''); 
  21. $max = 3; 
  22. $j = 0; 
  23. if(count($dirs) == 2){ 
  24. echo''
  25.  print(""); 
  26.  print('.$path."/".$dirs[0].'">'); 
  27.  print($dirs[0]); 
  28.  print(''); 
  29.  print(""); 
  30.  print(""); 
  31.  print('.$path."/".$dirs[1].'">'); 
  32.  print($dirs[1]); 
  33.  print(''); 
  34.  print(""); 
  35.  print(""); 
  36.  print("  "); 
  37.  print(""); 
  38.  echo ''
  39. }else
  40. echo''
  41. while($j <= (count($dirs) -1)){ 
  42.  print(""); 
  43.  print('.$path."/".$dirs[$j].'">'); 
  44.  print($dirs[$j]); 
  45.  print(''); 
  46.  print(""); 
  47.  if(($j + 1) % $max == 0){ 
  48.    echo ''
  49.    if(($j + 1) != count($dirs)){ 
  50.     echo ''
  51.      } 
  52.   } 
  53.   $j++; 
  54.  }  
  55.  echo ''
  56. $i = 0; 
  57. if(count($files) == 2){ 
  58. echo''
  59.  print(".$newdir -> getfiletype($files[0]).".png'/> "); 
  60.  print($newdir -> change2line($files[0])); 
  61.  print(""); 
  62.  print(".$newdir -> getfiletype($files[1]).".png'/> "); 
  63.  print($newdir -> change2line($files[1])); 
  64.  print(""); 
  65.  print(""); 
  66.  print("  "); 
  67.  print(""); 
  68.  echo ''
  69. }else
  70. echo''
  71. while($i <= (count($files) -1)){ 
  72.  print(".$newdir -> getfiletype($files[$i]).".png'/> "); 
  73.  print($newdir -> change2line($files[$i]));  
  74.  print("");//开源代码phpfensi.com 
  75.  if(($i + 1) % 3 == 0){ 
  76.    echo ''
  77.    if(($i + 1) != count($files)){ 
  78.     echo ''
  79.     } 
  80.  } 
  81.  
  82.  $i++; 
  83. }  
  84.  echo ''
  85. ?> 

class.php,代码如下:

  1.   class for php4.x 
  2.  class  dirver{ 
  3.   /class var
  4.   var $path
  5.   var $flies
  6.   var $dirs
  7.   / 
  8.   function dirver(){ 
  9.    $this -> path = "";  
  10.    $this -> files = array(); 
  11.    $this -> dirs = array(); 
  12.   } 
  13.    
  14.   function dirdata(){ 
  15.    if(isset($this -> path)){ 
  16.     $handle = dir($this -> path); 
  17.     while(false !== ($data = $handle -> read())){ 
  18.      if(is_dir($this -> connectname($this -> path,$data)) && $data != "." && $data != ".."){ 
  19.        $this -> dirs[] = $data
  20.        continue
  21.       } 
  22.        
  23.      if($data != "." && $data != ".." && is_file($this -> connectname($this -> path,$data))){ 
  24.        $this -> files[] = $data
  25.        continue
  26.       } 
  27.       
  28.     } 
  29.     $handle -> close();  
  30.    }else
  31.     return false;  
  32.    } 
  33.   } 
  34.    
  35.  function setpath($src){ 
  36.    if($src != ""){ 
  37.     $this -> path = $src;  
  38.    }else
  39.     return false;  
  40.    } 
  41.   } 
  42.  / 
  43.  function connectname($path,$name){ 
  44.   return $path."/".$name
  45.  } 
  46.  / 
  47.  function change2line($name){ 
  48.   $basename = explode(".",$name); 
  49.   $basename = $basename[0]; 
  50.   $tmp = $this -> path."/".$name
  51.   $tmp = '.$tmp.'" target="_blank">'.$basename.''
  52.   return $tmp;  
  53.  } 
  54.  
  55.  function getfiletype($file){ 
  56.   if($file != ""){ 
  57.    $tmp = explode(".",$file); 
  58.    $type = $tmp[count($tmp)-1]; 
  59.    return $type;  
  60.   } 
  61.  } 
  62.  
  63.  
  64.  function getfiles(){ 
  65.   return $this -> files; 
  66.   } 
  67.  
  68.  function getdirs(){ 
  69.   return $this -> dirs;  
  70.   } 
  71.  // 
  72.  } 
  73.  
  74.  
  75. ?> 
分享到:
php批量重命名文件名 - php文件操作
php批量重命名文件名 本程序分为简单的单文件重名,加上getfile就可以实现文件批量重命名了,$path为要你重命名的目录,它可以把指定目录下所指定文件类型的议论后次批量重命名,非常好用,代码如下: $format =&#039;php&#039;;  $path =&#039;www.phpfensi.com/&#039;;  $files = ...
支持多级目录建立的php函数 - php文件操...
支持多级目录建立的php函数 本函数php自定义函数是一款建立文件夹的路径并且支持多级目录实例函数,实例代码如下: * create_dir(建立文件夹的路径,支持多级目录);  */  function create_dir($dir_adds=&#039;&#039;) {   $falg = true;   $dir_adds  = trim($dir_...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……