PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/system/helpers/directory_helper.php

http://github.com/philsturgeon/codeigniter-restserver
PHP | 80 lines | 31 code | 10 blank | 39 comment | 10 complexity | a4ec4f5bb622993e2fe6f062eb9bc603 MD5 | raw file
Possible License(s): MIT
  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 ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter Directory Helpers
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Helpers
  21. * @category Helpers
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
  24. */
  25. // ------------------------------------------------------------------------
  26. /**
  27. * Create a Directory Map
  28. *
  29. * Reads the specified directory and builds an array
  30. * representation of it. Sub-folders contained with the
  31. * directory will be mapped as well.
  32. *
  33. * @access public
  34. * @param string path to source
  35. * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
  36. * @return array
  37. */
  38. if ( ! function_exists('directory_map'))
  39. {
  40. function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE)
  41. {
  42. if ($fp = @opendir($source_dir))
  43. {
  44. $filedata = array();
  45. $new_depth = $directory_depth - 1;
  46. $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
  47. while (FALSE !== ($file = readdir($fp)))
  48. {
  49. // Remove '.', '..', and hidden files [optional]
  50. if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.'))
  51. {
  52. continue;
  53. }
  54. if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file))
  55. {
  56. $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden);
  57. }
  58. else
  59. {
  60. $filedata[] = $file;
  61. }
  62. }
  63. closedir($fp);
  64. return $filedata;
  65. }
  66. return FALSE;
  67. }
  68. }
  69. /* End of file directory_helper.php */
  70. /* Location: ./system/helpers/directory_helper.php */