/system/helpers/directory_helper.php CI目录助手
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Directory Helpers * CI目录助手 * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/directory_helper.html */ // ------------------------------------------------------------------------ /** * Create a Directory Map * 创建一个指南地图与 * * Reads the specified directory and builds an array * representation of it. Sub-folders contained with the * directory will be mapped as well. * 读取指定的目录和构建一个数组表示。 * 与包含的子文件夹目录将被映射为。 * @access public * @param string path to source 路径源 * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) * 深度的目录遍历(0=完全递归,1 =当前目录等) * @return array */ if ( ! function_exists('directory_map')) { function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) { //打开目录opendir() if ($fp = @opendir($source_dir)) { $filedata = array(); //声明文件数组 //目录的深度 $new_depth = $directory_depth - 1; //将$source_dir 用系统定义的目录符替换为空,然后拼接一下DIRECTORY_SEPARATOR $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; //开始循环该目录 下面每一个文件 while (FALSE !== ($file = readdir($fp))) { // Remove '.', '..', and hidden files [optional] // 删除'。','..',和隐藏文件[可选] if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.')) { continue; } //眼目录的层次要求小于1或者$new_depth大于0的时候,并且该文件为一个目录时,进行递归 if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file)) { $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden); } else { $filedata[] = $file; } } closedir($fp); return $filedata; } return FALSE; } } /* End of file directory_helper.php */ /* Location: ./system/helpers/directory_helper.php */