admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 15 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Code Igniter Directory Helpers |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Helpers |
| 23 | * @category Helpers |
| 24 | * @author Rick Ellis |
| 25 | * @link http://www.codeigniter.com/user_guide/helpers/directory_helper.html |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
admin | e7e1dcd | 2006-10-21 18:04:01 +0000 | [diff] [blame] | 31 | * Create a Directory Map |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 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 | */ |
| 42 | function directory_map($source_dir, $top_level_only = FALSE) |
admin | c1e23ce | 2006-10-23 20:49:27 +0000 | [diff] [blame] | 43 | { |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 44 | if ($fp = @opendir($source_dir)) |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 45 | { |
admin | c1e23ce | 2006-10-23 20:49:27 +0000 | [diff] [blame] | 46 | $filedata = array(); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 47 | while (FALSE !== ($file = readdir($fp))) |
| 48 | { |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 49 | if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE) |
| 50 | { |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 51 | $temp_array = array(); |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 52 | |
| 53 | $temp_array = directory_map($source_dir.$file."/"); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 54 | |
| 55 | $filedata[$file] = $temp_array; |
| 56 | } |
| 57 | elseif (substr($file, 0, 1) != ".") |
| 58 | { |
| 59 | $filedata[] = $file; |
| 60 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 61 | } |
| 62 | return $filedata; |
| 63 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | |
| 67 | ?> |