Beispiel #1
0
/**
 * 扫描目录所有文件,并生成treegrid数据
 * @param string $path     目录
 * @param string $filter   过滤文件名
 * @param number $i        辅助用,这个不用传参
 * @return array
 */
function scandir_tree($path, $filter = SITE_DIR, &$i = 1)
{
    $result = array();
    $path = realpath($path);
    $path = str_replace(array('/', '\\'), DS, $path);
    $filter = str_replace(array('/', '\\'), DS, $filter);
    $list = glob($path . DS . '*');
    foreach ($list as $key => $filename) {
        $result[$key]['id'] = $i;
        $result[$key]['name'] = str_replace($filter, '', $filename);
        $i++;
        if (is_dir($filename)) {
            $result[$key]['type'] = 'dir';
            $result[$key]['size'] = '-';
            $result[$key]['mtime'] = '-';
            $result[$key]['state'] = 'closed';
            $result[$key]['children'] = scandir_tree($filename, $filter, $i);
            //easyui当children为空时会出现问题,因此在这里过滤
            if (empty($result[$key]['children'])) {
                $result[$key]['iconCls'] = 'tree-folder';
                unset($result[$key]['state']);
                unset($result[$key]['children']);
            }
        } else {
            $result[$key]['type'] = 'file';
            $result[$key]['size'] = format_bytes(filesize($filename), ' ');
            $result[$key]['mtime'] = date('Y-m-d H:i:s', filemtime($filename));
        }
    }
    return $result;
}
 /**
  * 文件列表
  */
 public function fileList()
 {
     $menu_db = D('Menu');
     if (IS_POST) {
         $data = scandir_tree($this->fileBathPath, $this->fileBathPath);
         $this->ajaxReturn($data);
     } else {
         $currentpos = $menu_db->currentPos(I('get.menuid'));
         //栏目位置
         $treegrid = array('options' => array('title' => $currentpos, 'url' => U('System/fileList', array('grid' => 'treegrid')), 'idField' => 'id', 'treeField' => 'name'), 'fields' => array('名称' => array('field' => 'name', 'width' => 200), '文件大小' => array('field' => 'size', 'width' => 40), '修改时间' => array('field' => 'mtime', 'width' => 60), '管理操作' => array('field' => 'id', 'width' => 60, 'align' => 'center', 'formatter' => 'systemFileOperateFormatter')));
         $this->assign('treegrid', $treegrid);
         $this->display('file_list');
     }
 }