关于PHP遍及文件目录及子文件夹文件的问题

浏览:788 发布日期:2013/12/03 分类:求助交流
现在遇到一个非常无解的问题,用下面的tree()方法来读取一个文件夹中的内容时,
页面直接会卡死,检查了路径,没有发现问题, 传入的参数也是对的。function tree($path,$directory) {
    
    $handler = opendir($path."/".$directory); 
    while( ($file = readdir($handler)) !== false){
        //natcasesort($file);
        //$file = iconv("GB2312", "UTF-8", $file);
        if($file != "." && $file != ".."){
            if(is_dir($path."/".$directory."/".$file))
            {
                echo '<li>';
                echo '<a href="#" class="tree-toggle closed" data-toggle="branch" 
                    data-value="Bootstrap_Tree"><span class="dirtitle">'.$file.'</span><span style="color:#ccc"> 更新于 '.date('Y-m-d H:i',filemtime($path."/".$directory."/".$file)).'</span></a>'; 
                echo '<ul class="branch">';
                tree($path."/".$directory.'/'.$file); 
                echo '</ul>';
                echo '</li>';
            } 
            else {
                $files[] = $file;
                sort($files);    
            }
        }
    }
    
    foreach($files as $v){
        
        echo '<li><a href="__ROOT__/'.$path.'/'.$directory.'/'.$v.'" data-role="leaf" target="_blank">
                        <i class="icon-list-alt"></i> '.$v.'</a>
                     </li>'; 
    };

    closedir($handler);
比如我想遍历根目录下的这个文件夹:
./appendix/rd
其里面还有三个子文件夹,分别是:
file1, file2, file3

控制器里面写了一个数组变量:        protected $filesDirs = array(
        //流程管理所在附件的目录
        'rd'=>'./appendix/rd', 
    );
然后调用这个变量: public function index(){
         $f = $this->filesDirs;
         $this->f = $f;
         $this->title();
         $this->display();
    }
前台模板输出时这样写的,想遍历出file1里面的文件:

<ul class="tree" id="tree_1">{:tree($f['rd'],'file1'}</ul>

结果直接卡死
这是什么原因造成的呢???


最佳答案
评论( 相关
后面还有条评论,点击查看>>