blob: e6ed47fd82284c75ca9c6f21e82721c4a04cff47 [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?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.
admine334c472006-10-21 19:44:22 +000010 * @license http://www.codeignitor.com/user_guide/license.html
adminb0dd10f2006-08-25 17:25:49 +000011 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
admine334c472006-10-21 19:44:22 +000015
adminb0dd10f2006-08-25 17:25:49 +000016// ------------------------------------------------------------------------
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/**
admine7e1dcd2006-10-21 18:04:01 +000031 * Create a Directory Map
adminb0dd10f2006-08-25 17:25:49 +000032 *
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 */
42function directory_map($source_dir, $top_level_only = FALSE)
43{
44 if ( ! isset($filedata))
45 $filedata = array();
46
47 if ($fp = @opendir($source_dir))
admine334c472006-10-21 19:44:22 +000048 {
adminb0dd10f2006-08-25 17:25:49 +000049 while (FALSE !== ($file = readdir($fp)))
50 {
admine334c472006-10-21 19:44:22 +000051 if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)
52 {
adminb0dd10f2006-08-25 17:25:49 +000053 $temp_array = array();
admine334c472006-10-21 19:44:22 +000054
55 $temp_array = directory_map($source_dir.$file."/");
adminb0dd10f2006-08-25 17:25:49 +000056
57 $filedata[$file] = $temp_array;
58 }
59 elseif (substr($file, 0, 1) != ".")
60 {
61 $filedata[] = $file;
62 }
admine334c472006-10-21 19:44:22 +000063 }
64 return $filedata;
65 }
adminb0dd10f2006-08-25 17:25:49 +000066}
67
68
69?>