directory_helper.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author EllisLab Dev Team
  9. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
  10. * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
  11. * @license http://codeigniter.com/user_guide/license.html
  12. * @link http://codeigniter.com
  13. * @since Version 1.0
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * CodeIgniter Directory Helpers
  19. *
  20. * @package CodeIgniter
  21. * @subpackage Helpers
  22. * @category Helpers
  23. * @author EllisLab Dev Team
  24. * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
  25. */
  26. // ------------------------------------------------------------------------
  27. /**
  28. * Create a Directory Map
  29. *
  30. * Reads the specified directory and builds an array
  31. * representation of it. Sub-folders contained with the
  32. * directory will be mapped as well.
  33. *
  34. * @access public
  35. * @param string path to source
  36. * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
  37. * @return array
  38. */
  39. if ( ! function_exists('directory_map'))
  40. {
  41. function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE)
  42. {
  43. if ($fp = @opendir($source_dir))
  44. {
  45. $filedata = array();
  46. $new_depth = $directory_depth - 1;
  47. $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
  48. while (FALSE !== ($file = readdir($fp)))
  49. {
  50. // Remove '.', '..', and hidden files [optional]
  51. if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.'))
  52. {
  53. continue;
  54. }
  55. if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file))
  56. {
  57. $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden);
  58. }
  59. else
  60. {
  61. $filedata[] = $file;
  62. }
  63. }
  64. closedir($fp);
  65. return $filedata;
  66. }
  67. return FALSE;
  68. }
  69. }
  70. /* End of file directory_helper.php */
  71. /* Location: ./system/helpers/directory_helper.php */