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

PHP
PHP 柱状图实现代码
PHP 用数组降低程序的时间复杂度
PHP 读取文件内容代码(txt,js等)
Php 构造函数construct的前下划线是双的_
PHP 采集程序中常用的函数
一个比较简单的PHP 分页分组类
php下图片文字混合水印与缩略图实现代码
php5 图片验证码实现代码
phpmyadmin导入(import)文件限制的解决办法
php smarty模版引擎中变量操作符及使用方法
Php Mssql操作简单封装支持存储过程
php实现的仿阿里巴巴实现同类产品翻页
php入门教程 精简版
将文件夹压缩成zip文件的php代码
PHP开发过程中常用函数收藏
php csv操作类代码
php遍历目录viewDir函数
PHP 基本语法格式
php生成xml简单实例代码
PHP下编码转换函数mb_convert_encoding与iconv的使用说明

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


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