blob: ad868519da7af3ecae227649c41f9e0b27fbe245 [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)
adminc1e23ce2006-10-23 20:49:27 +000043{
adminb0dd10f2006-08-25 17:25:49 +000044 if ($fp = @opendir($source_dir))
admine334c472006-10-21 19:44:22 +000045 {
adminc1e23ce2006-10-23 20:49:27 +000046 $filedata = array();
adminb0dd10f2006-08-25 17:25:49 +000047 while (FALSE !== ($file = readdir($fp)))
48 {
admine334c472006-10-21 19:44:22 +000049 if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)
50 {
adminb0dd10f2006-08-25 17:25:49 +000051 $temp_array = array();
admine334c472006-10-21 19:44:22 +000052
53 $temp_array = directory_map($source_dir.$file."/");
adminb0dd10f2006-08-25 17:25:49 +000054
55 $filedata[$file] = $temp_array;
56 }
57 elseif (substr($file, 0, 1) != ".")
58 {
59 $filedata[] = $file;
60 }
admine334c472006-10-21 19:44:22 +000061 }
62 return $filedata;
63 }
adminb0dd10f2006-08-25 17:25:49 +000064}
65
66
67?>