134 lines
3.8 KiB
PHP
134 lines
3.8 KiB
PHP
<?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)){
|
|
$msg['error'] = "请先登录";
|
|
echo Zend_Json::encode($msg);
|
|
exit();
|
|
}
|
|
|
|
$files=new files();
|
|
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'reviewatt');
|
|
|
|
if(empty($msg['error']))
|
|
{
|
|
$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'];
|
|
$msg['html'] = $realname.'[已完成]<input type="hidden" name="atts[]" value="'.$attid.'" /><div class="cancel"><a href="javascript:;" id="deletebtn_'.$attid.'"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
|
|
echo Zend_Json::encode($msg);
|
|
exit();
|
|
}else{
|
|
$msg['error'] = '附件上传失败:'.$msg['error'];
|
|
@unlink($filename);
|
|
echo Zend_Json::encode($msg);
|
|
exit();
|
|
}
|
|
|
|
}catch(Exception $e){
|
|
$msg['error'] = "错误:".$e->getMessage();
|
|
echo Zend_Json::encode($msg);
|
|
exit();
|
|
}
|
|
|
|
}//indexAction()
|
|
|
|
/*
|
|
获得单个文件的信息
|
|
return array row
|
|
*/
|
|
public function getFileinfo($id){
|
|
$sql = "select * from attachments where id='$id'";
|
|
$re= $this->db->query($sql);
|
|
$row= $re->fetch();
|
|
return $row;
|
|
}
|
|
|
|
function delreviewattAction(){
|
|
$this->_helper->layout()->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
$id = $this->_request->getParam('id');
|
|
$basepath = $this->view->config->upload;
|
|
$info = $this->getFileinfo($id);
|
|
$filepath = $basepath.$info['filename'];
|
|
try{
|
|
$auth = Zend_Auth::getInstance();
|
|
if($auth->hasIdentity())
|
|
{
|
|
$user = $auth->getIdentity();
|
|
$userid = $user->id;
|
|
$sql = "delete from attachments where id='$id' and userid='$userid'";
|
|
if($this->db->exec($sql)>0)
|
|
{
|
|
@unlink($filepath);
|
|
}
|
|
}
|
|
|
|
}catch(Exception $e){}
|
|
//不输出任何错误
|
|
}//删除评审附件
|
|
|
|
function getattsAction(){
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
$id = $this->_request->getParam('id');
|
|
|
|
if($id!='')
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
if($auth->hasIdentity())
|
|
{
|
|
$user = $auth->getIdentity();
|
|
$userid = $user->id;
|
|
$sql = "select att.realname,att.id from attachments att
|
|
left join mdreviewattach ratt on att.id=ratt.attachid
|
|
where ratt.reviewid=$id and att.userid=$userid";
|
|
$rs = $this->db->query($sql);
|
|
$atts = $rs->fetchAll();
|
|
foreach($atts as $k=>$v)
|
|
{
|
|
$atts[$k]['html']=$v['realname'].'[已完成]<input type="hidden" name="atts[]" value="'.$v['id'].'" /><div class="cancel"><a href="javascript:;" id="deletebtn_'.$v['id'].'"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
|
|
}
|
|
echo Zend_Json::encode($atts);
|
|
exit();
|
|
}else
|
|
{
|
|
exit();
|
|
}
|
|
}else{
|
|
exit();
|
|
}
|
|
//不输出错误
|
|
}//获取附件
|
|
|
|
} |