From 96dafa84d2c6e1f7792e67d0ea0bc81c69543894 Mon Sep 17 00:00:00 2001
From: Robin Sowell
Date: Tue, 26 May 2009 21:45:54 +0000
Subject: Directory helper's directory_map tweaked to allow inclusion of hidden
files.
---
system/helpers/directory_helper.php | 6 +++---
user_guide/changelog.html | 1 +
user_guide/helpers/directory_helper.html | 7 +++++--
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php
index 5f67b126f..b1c497686 100644
--- a/system/helpers/directory_helper.php
+++ b/system/helpers/directory_helper.php
@@ -41,7 +41,7 @@
*/
if ( ! function_exists('directory_map'))
{
- function directory_map($source_dir, $top_level_only = FALSE)
+ function directory_map($source_dir, $top_level_only = FALSE, $hidden = FALSE)
{
if ($fp = @opendir($source_dir))
{
@@ -50,7 +50,7 @@ if ( ! function_exists('directory_map'))
while (FALSE !== ($file = readdir($fp)))
{
- if (strncmp($file, '.', 1) == 0)
+ if (($hidden == FALSE && strncmp($file, '.', 1) == 0) OR ($file == '.' OR $file == '..'))
{
continue;
}
@@ -59,7 +59,7 @@ if ( ! function_exists('directory_map'))
{
$temp_array = array();
- $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR);
+ $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, $hidden);
$filedata[$file] = $temp_array;
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index c423ac6e7..3ae2cb612 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -82,6 +82,7 @@ SVN Revision:
- Added form_multiselect() to the Form helper.
- Modified form_hidden() in the Form helper to accept multi-dimensional arrays.
+ - Modified directory_map() in the Directory helper to allow the inclusion of hidden files.
diff --git a/user_guide/helpers/directory_helper.html b/user_guide/helpers/directory_helper.html
index 898b5ac0b..5ebb816f6 100644
--- a/user_guide/helpers/directory_helper.html
+++ b/user_guide/helpers/directory_helper.html
@@ -78,13 +78,16 @@ and builds an array representation of it and all its contained files. Example:
Note: Paths are almost always relative to your main index.php file.
-
-
Sub-folders contained within the directory will be mapped as well. If you wish to map
only the top level directory set the second parameter to true (boolean):
$map = directory_map('./mydirectory/', TRUE);
+By default, hidden files will not be included in the returned array. To override this behavior,
+you may set a third parameter to true (boolean):
+
+$map = directory_map('./mydirectory/', FALSE, TRUE);
+
Each folder name will be an array index, while its contained files will be numerically indexed.
Here is an example of a typical array:
--
cgit v1.2.3-24-g4f1b