directory_helper.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2008, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * CodeIgniter Directory Helpers
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Helpers
00023  * @category    Helpers
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/helpers/directory_helper.html
00026  */
00027 
00028 // ------------------------------------------------------------------------
00029 
00030 /**
00031  * Create a Directory Map
00032  *
00033  * Reads the specified directory and builds an array
00034  * representation of it.  Sub-folders contained with the
00035  * directory will be mapped as well.
00036  *
00037  * @access      public
00038  * @param       string  path to source
00039  * @param       bool    whether to limit the result to the top level only
00040  * @return      array
00041  */     
00042 if ( ! function_exists('directory_map'))
00043 {
00044         function directory_map($source_dir, $top_level_only = FALSE)
00045         {       
00046                 if ($fp = @opendir($source_dir))
00047                 {
00048                         $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;              
00049                         $filedata = array();
00050                         
00051                         while (FALSE !== ($file = readdir($fp)))
00052                         {
00053                                 if (strncmp($file, '.', 1) == 0)
00054                                 {
00055                                         continue;
00056                                 }
00057                                 
00058                                 if ($top_level_only == FALSE && @is_dir($source_dir.$file))
00059                                 {
00060                                         $temp_array = array();
00061                                 
00062                                         $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR);
00063                                 
00064                                         $filedata[$file] = $temp_array;
00065                                 }
00066                                 else
00067                                 {
00068                                         $filedata[] = $file;
00069                                 }
00070                         }
00071                         
00072                         closedir($fp);
00073                         return $filedata;
00074                 }
00075         }
00076 }
00077 
00078 
00079 /* End of file directory_helper.php */
00080 /* Location: ./system/helpers/directory_helper.php */