I am using dircetory_helper() to list all directories and files. However, when I change the permissions of a folder to 0700 (so it cannot be seen or accessed), it is still appearing in the array. Like so;
Array
(
[2001-07-01/] => Array
(
[0] => 1_july_2001.pdf
)
[0] => introduction.html
[2009-05-01/] =>
[2012-07-01/] => Array
(
[0] => 1_july_2012.pdf
[1] => 1_july_2012.xls
)
[2013-01-01/] => Array
(
[0] => 1_january_2013.pdf
[1] => key_points.html
[2] => 1_january_2013.xls
)
)
Look at the 2009-05-01/ key. I do not want this to appear in the array. At the moment it is appearing as an array key but what is the item? Is it NULL?
Is there a fix for this? I am using codeigniter version 2.1.3
At the moment it is appearing as an array key but what is the item? Is it NULL?
It is an empty array. Is is boolean (false). So long as it's not showing the contents, what is the problem? When you are displaying the array, there isn't anything in the array so it (nor it's key) should be displayed.
if( count($array_item) == 0 )
{
// dont show $array_item
}
else
{
// $array_item with stuff in it; display
}
I don't think there is a way to prevent the key from getting in there without changing the permissions on the parent directory which will then obviously prevent the rest of the dir's from being read too. By changing the folder to 0700
, it is acting as expected by not rendering the contents of the directory.
However, you can modify the result of directory_map()
before sending it back:
$this->load->helper('directory');
$map = directory_map('testdir');
$my_map = array();
foreach($map as $k => $v )
{
// check that it's not an empty array and that it's not a file
// in the root directory
if($v and gettype($v) == 'array')
{
$my_map[$k] = $v;
}
}
print_r($my_map);