blob: 25c16c1fc1e89edf17a081e51b2d4d5bda84b88a [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter Directory Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Create a Directory Map
32 *
33 * Reads the specified directory and builds an array
34 * representation of it. Sub-folders contained with the
35 * directory will be mapped as well.
36 *
37 * @access public
38 * @param string path to source
39 * @param bool whether to limit the result to the top level only
40 * @return array
41 */
Derek Jones269b9422008-01-28 21:00:20 +000042if (! function_exists('directory_map'))
43{
44 function directory_map($source_dir, $top_level_only = FALSE)
45 {
46 if ($fp = @opendir($source_dir))
Derek Allardd2df9bc2007-04-15 17:41:17 +000047 {
Derek Jones2798b502008-05-06 14:12:18 +000048 $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
Derek Jones269b9422008-01-28 21:00:20 +000049 $filedata = array();
Derek Jones2798b502008-05-06 14:12:18 +000050
Derek Jones269b9422008-01-28 21:00:20 +000051 while (FALSE !== ($file = readdir($fp)))
Derek Allardd2df9bc2007-04-15 17:41:17 +000052 {
Derek Jones2798b502008-05-06 14:12:18 +000053 if (substr($file, 0, 1) == '.')
54 {
55 continue;
56 }
57
58 if ($top_level_only == FALSE && @is_dir($source_dir.$file))
Derek Jones269b9422008-01-28 21:00:20 +000059 {
60 $temp_array = array();
Derek Allardd2df9bc2007-04-15 17:41:17 +000061
Derek Jones2798b502008-05-06 14:12:18 +000062 $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR);
Derek Allardd2df9bc2007-04-15 17:41:17 +000063
Derek Jones269b9422008-01-28 21:00:20 +000064 $filedata[$file] = $temp_array;
65 }
Derek Jones2798b502008-05-06 14:12:18 +000066 else
Derek Jones269b9422008-01-28 21:00:20 +000067 {
68 $filedata[] = $file;
69 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000070 }
Derek Jones2798b502008-05-06 14:12:18 +000071
72 closedir($fp);
Derek Jones269b9422008-01-28 21:00:20 +000073 return $filedata;
Derek Allardd2df9bc2007-04-15 17:41:17 +000074 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000075 }
76}
77
adminb0dd10f2006-08-25 17:25:49 +000078?>