model = model('Attachment'); } /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model ->where($where) ->order($sort, $order) ->count(); $list = $this->model ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->select(); $cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root()); foreach ($list as $k => &$v) { if (filter_var($v['url'], FILTER_VALIDATE_URL)) { //验证路径是否为完整URL格式 $v['fullurl'] = $v['url']; } else { $v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url']; } } unset($v); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 选择附件 */ public function select() { if ($this->request->isAjax()) { return $this->index(); } return $this->view->fetch(); } /** * 添加 */ public function add() { if ($this->request->isAjax()) { $this->error(); } return $this->view->fetch(); } public function del($ids = "") { if ($ids) { $count = $this->model->destroy($ids); if ($count) { \think\Hook::listen("upload_after", $this); $this->success(); } } $this->error(__('Parameter %s can not be empty', 'ids')); } }