/**
  * 上传
  */
 public function addAction()
 {
     if ($this->_request->isPost()) {
         $post = $this->_request->getPost();
         $post['uid'] = $this->auths->uid;
         $fileData = $_FILES['file'];
         $data = $this->file->add($post, $fileData, false);
         $this->_redirect($this->view->url(array('action' => 'list')));
     }
     $this->view->cateId = $this->_getParam('id');
     $select = $this->file->cateListSql()->where('cate.allow_upload=1');
     $this->view->categories = $this->db->fetchAll($select);
 }
Ejemplo n.º 2
0
 public function addClicked(SubmitButton $button)
 {
     $array = $button->getForm()->getValues();
     if ($array['authorId'] == 'true') {
         $array['author'] = dibi::query('SELECT authorId FROM authors ORDER BY authorId DESC LIMIT 1')->fetchSingle();
     } elseif ($array['author'] == 0) {
         $this->flashMessage('Je potřaba vybrat autora!', 'error');
         return;
     }
     unset($array['authorId']);
     try {
         $array['url'] = Model::createUri($array['title'], $array['author']);
     } catch (Exception $e) {
         $this->flashMessage('U tohoto autora byla již vložena práce se stejným jménem', 'error');
         return;
     }
     $array['added%sql'] = 'NOW()';
     $array['edited%sql'] = 'NOW()';
     $array = $this->fixValues($array);
     $file = $array['file'];
     unset($array['file']);
     $id = Model::add($array, 'works');
     if ($file != '') {
         FileModel::add($id, $_FILES['file']);
     }
     $s = Environment::getSession('workform');
     $s->author = $array['author'];
     $s->award = $array['award'];
     $s->year = $array['year'];
     $s->type = $array['type'];
     $this->flashMessage('Práce byla přidána.', 'info');
     $this->redirect("this");
 }
Ejemplo n.º 3
0
 /**
  * 上传文件
  * POST /file/
  * @method POST_index
  * @param key 获取token时返回的key
  */
 public function POST_indexAction()
 {
     if (!Input::post('key', $key, 'filename')) {
         $this->response(0, '未收到数据');
         return;
     }
     list(, $userid) = explode('_', $key, 3);
     $userid = $this->auth($userid);
     $response['status'] = 0;
     if (!($name = Cache::get($key))) {
         $response['info'] = '文件不存在';
     } else {
         Cache::del($key);
         /*文件名由 t_xxxx,重命名为 f_xxxx*/
         $bucket = Config::getSecret('qiniu', 'file');
         $uri = $bucket . ':f_' . substr($key, 2);
         $file['name'] = $name;
         $file['url'] = $uri;
         $file['use_id'] = $userid;
         if (!File::set($bucket . ':' . $key, $uri)) {
             $response['info'] = '文件校验失败';
         } elseif (!($fid = FileModel::add($file))) {
             $response['info'] = '文件保存失败';
         } else {
             $response['status'] = 1;
             $response['info'] = ['msg' => '保存成功', 'id' => $fid];
         }
     }
     $this->response = $response;
 }