当前位置: 首页 > 图文教程 > 网络编程 > PHP > listdir($dir) 目录读取函数

PHP
PHP中for循环语句的几种“变态”用法
用PHP与XML联手进行网站开发
PHP程序漏洞产生的原因和防范方法
利用PHP编程防范XSS跨站脚本攻击
使用PHP往Windows系统中添加用户
PHP Shell的编写(改进版)
PHP开发中接收复选框信息的方法
PHP程序加速探索之服务器负载测试
PHP实现首页自动选择语言转跳
十天学会php之第一天
十天学会php之第二天
十天学会php之第三天
十天学会php之第四天
十天学会php之第五天
十天学会php之第六天
十天学会php之第七天
十天学会php之第八天
十天学会php之第九天
十天学会php之第十天
Web开发源代码:PHP生成静态页面的类

PHP 中的 listdir($dir) 目录读取函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-19   浏览: 391 ::
收藏到网摘: n/a

  1. /** 
  2. * @ 目录读取函数, $start_dir 目录 
  3. */  
  4. function listdir($start_dir='.') {  
  5.   $files = array();  
  6.   if (is_dir($start_dir)) {  
  7.     $fh = opendir($start_dir);  
  8.     while (($file = readdir($fh)) !== false) {  
  9.       if (strcmp($file'.')==0 || strcmp($file'..')==0) continue;  
  10.       $filepath = $start_dir . '/' . $file;  
  11.       if ( is_dir($filepath) ) $files = array_merge($files, listdir($filepath));  
  12.       else array_push($files$filepath);  
  13.     }  
  14.     closedir($fh);  
  15.   }  
  16.   else {  
  17.     $files = false;  
  18.   }  
  19.   return $files;