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

PHP
PHP技巧教程:setcookie语句的问题
多个字段,大量记录的插入操作技巧(PHP)
动态网页PHP脚本中include文件报错解决方法
PHP中类的使用,面向对象的思路
php+javascript 静态化简单实例
Zend Framework留言本模型文件 (PHP源码)
PHP中使用ASP.NET AJAX
PHP正则表达式的快速学习方法
php中防盗链使用.htaccess
PHP在windows和LINUX下的路径分隔符
php页面zend加密乱码的解决办法
PHP中如何使用header发送头部信息
如何将PHP中的多维数组显示出来
用PHP操作MySql数据库(分页)
保护代码安全,PHP如何进行注入
在PHP中使用全局变量【一】
在PHP中使用全局变量【二】
获取远程图片并把它保存到本地
源代码的加亮(highlight_file)
用PHP上传文件和发送邮件

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


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