增加了通用的ajax上传附件接口(仅接收来自uploadify的数据)
This commit is contained in:
parent
888b3c76fa
commit
5c66d3df05
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue