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

PHP
在PHP中以root身份运行外部命令
PHP编程常用技巧四则
实例学习PHP之投票程序篇
PHP中的加密功能
PHP VS ASP
PHP生成动态WAP页面
PHP中for循环语句的几种变型
PHP5.0对象模型探索之对象串行化
PHP5.0对象模型探索之重载
浅议PHP程序开发中的模板选择
用PHP写的身份证验证程序
PHP.MVC的模板标签系统之初识PHP.MVC
PHP程序加速探索之代码优化
PHP程序加速探索之压缩输出gzip
用PHP文件上传的具体思路及实现
使用PHP编写基于Web的文件管理系统
理解PHP中的MVC编程之控制器
PHP程序加速探索之缓存输出
让你的PHP引擎全速运转的三个绝招
PHP程序加速探索之加速工具软件

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-19   浏览: 416 ::
收藏到网摘: 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;