//文件/夹管理 public function browseFile($spath = '', $stype = 'file') { $base_path = '/uploads/img1'; $enocdeflag = I('encodeflag', 0, 'intval'); switch ($stype) { case 'picture': $base_path = '/uploads/img1'; break; case 'file': $base_path = '/uploads/file1'; break; case 'ad': $base_path = '/uploads/abc1'; break; default: exit('参数错误'); break; } if ($enocdeflag) { $spath = base64_decode($spath); } $spath = str_replace('.', '', $spath); if (strpos($spath, $base_path) === 0) { $spath = substr($spath, strlen($base_path)); } $path = $base_path . '/' . $spath; $path = str_replace('//', '/', $path); $dir = new \Common\Lib\Dir('.' . $path); //加上. $list = $dir->toArray(); for ($i = 0; $i < count($list); $i++) { $list[$i]['isImg'] = 0; if ($list[$i]['isFile']) { $url = __ROOT__ . rtrim($path, '/') . '/' . $list[$i]['filename']; $ext = explode('.', $list[$i]['filename']); $ext = end($ext); if (in_array($ext, array('jpg', 'png', 'gif'))) { $list[$i]['isImg'] = 1; } } else { //为了兼容URL_MODEL(1、2) if (in_array(C('URL_MODEL'), array(1, 2, 3))) { $url = U('Public/browseFile', array('stype' => $stype, 'encodeflag' => 1, 'spath' => base64_encode(rtrim($path, '/') . '/' . $list[$i]['filename']))); } else { $url = U('Public/browseFile', array('stype' => $stype, 'spath' => rtrim($path, '/') . '/' . $list[$i]['filename'])); } } $list[$i]['url'] = $url; $list[$i]['size'] = get_byte($list[$i]['size']); } //p($list); $parentpath = substr($path, 0, strrpos($path, '/')); //为了兼容URL_MODEL(1、2) if (in_array(C('URL_MODEL'), array(1, 2, 3))) { $purl = U('Public/browseFile', array('spath' => base64_encode($parentpath), 'encodeflag' => 1, 'stype' => $stype)); } else { $purl = U('Public/browseFile', array('spath' => $parentpath, 'stype' => $stype)); } $this->assign('purl', $purl); $this->assign('vlist', $list); $this->assign('stype', $stype); $this->assign('type', '浏览文件'); //解析到模板