From 5c66d3df056a74f999c436261aa209a4a896b16d Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 3 Nov 2011 09:52:47 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=9A=84ajax=E4=B8=8A=E4=BC=A0=E9=99=84=E4=BB=B6=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=88=E4=BB=85=E6=8E=A5=E6=94=B6=E6=9D=A5=E8=87=AA?= =?UTF-8?q?uploadify=E7=9A=84=E6=95=B0=E6=8D=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/UploadController.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 application/default/controllers/UploadController.php diff --git a/application/default/controllers/UploadController.php b/application/default/controllers/UploadController.php new file mode 100644 index 00000000..c73d563f --- /dev/null +++ b/application/default/controllers/UploadController.php @@ -0,0 +1,57 @@ +db=Zend_Registry::get('db'); + $this->view->config = Zend_Registry::get('config'); + } + + function indexAction() { + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + try{ + $auth = Zend_Auth::getInstance(); + + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + } + + if(empty($userid)||!is_numeric($userid)){ + echo "请先登录"; + exit(); + } + + $files=new files(); + $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'reviewatt'); + + if(empty($msg['error'])) + { + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = $this->_request->getParam('dir'); + $realname = $msg['realname']; + + $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','reviewatt','$filedesc','$userid','$filesize','$realname') RETURNING id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $att = $sth->fetch(PDO::FETCH_ASSOC); + $msg['attid'] = $attid = $att['id']; + echo Zend_Json::encode($msg); + exit(); + }else{ + $this->messenger->addMessage('附件上传失败:'.$msg['error']); + @unlink($filename); + $this->_redirect($redirectlink); + } + + }catch(Exception $e){ + echo "错误:".$e->getMessage(); + exit(); + } + + } + +} \ No newline at end of file