增加了通用的ajax上传附件接口(仅接收来自uploadify的数据)

This commit is contained in:
Li Jianxuan 2011-11-03 09:52:47 +00:00
parent 888b3c76fa
commit 5c66d3df05
1 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,57 @@
<?php
class UploadController extends Zend_Controller_Action {
function preDispatch()
{
$this->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();
}
}
}