Take two:
[www-register-wizard.git] / helpers / directory_helper.php
1 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
2 /**\r
3  * CodeIgniter\r
4  *\r
5  * An open source application development framework for PHP 4.3.2 or newer\r
6  *\r
7  * @package             CodeIgniter\r
8  * @author              ExpressionEngine Dev Team\r
9  * @copyright   Copyright (c) 2008, EllisLab, Inc.\r
10  * @license             http://codeigniter.com/user_guide/license.html\r
11  * @link                http://codeigniter.com\r
12  * @since               Version 1.0\r
13  * @filesource\r
14  */\r
15 \r
16 // ------------------------------------------------------------------------\r
17 \r
18 /**\r
19  * CodeIgniter Directory Helpers\r
20  *\r
21  * @package             CodeIgniter\r
22  * @subpackage  Helpers\r
23  * @category    Helpers\r
24  * @author              ExpressionEngine Dev Team\r
25  * @link                http://codeigniter.com/user_guide/helpers/directory_helper.html\r
26  */\r
27 \r
28 // ------------------------------------------------------------------------\r
29 \r
30 /**\r
31  * Create a Directory Map\r
32  *\r
33  * Reads the specified directory and builds an array\r
34  * representation of it.  Sub-folders contained with the\r
35  * directory will be mapped as well.\r
36  *\r
37  * @access      public\r
38  * @param       string  path to source\r
39  * @param       bool    whether to limit the result to the top level only\r
40  * @return      array\r
41  */     \r
42 if ( ! function_exists('directory_map'))\r
43 {\r
44         function directory_map($source_dir, $top_level_only = FALSE)\r
45         {       \r
46                 if ($fp = @opendir($source_dir))\r
47                 {\r
48                         $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;              \r
49                         $filedata = array();\r
50                         \r
51                         while (FALSE !== ($file = readdir($fp)))\r
52                         {\r
53                                 if (strncmp($file, '.', 1) == 0)\r
54                                 {\r
55                                         continue;\r
56                                 }\r
57                                 \r
58                                 if ($top_level_only == FALSE && @is_dir($source_dir.$file))\r
59                                 {\r
60                                         $temp_array = array();\r
61                                 \r
62                                         $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR);\r
63                                 \r
64                                         $filedata[$file] = $temp_array;\r
65                                 }\r
66                                 else\r
67                                 {\r
68                                         $filedata[] = $file;\r
69                                 }\r
70                         }\r
71                         \r
72                         closedir($fp);\r
73                         return $filedata;\r
74                 }\r
75         }\r
76 }\r
77 \r
78 \r
79 /* End of file directory_helper.php */\r
80 /* Location: ./system/helpers/directory_helper.php */