duanqun9618 2013-10-02 12:20
浏览 81
已采纳

codeigniter目录映射助手 - 文件夹权限

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

  • 写回答

1条回答 默认 最新

  • dongmaoluan5719 2013-10-02 13:08
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler