diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 0fc20009..a2e01b81 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -1212,6 +1212,16 @@ class DataController extends Zend_Controller_Action if(!empty($uuid)) { + + $sql="select * from mdattach m left join attachments a on m.id=a.id where m.uuid='$uuid'"; + $re=$this->db->query($sql); + $atts = $re->fetch(); + + if(empty($atts['id'])) + { + $this->_redirect("/data/$uuid"); + }//没有附件 + $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { @@ -1421,97 +1431,6 @@ class DataController extends Zend_Controller_Action - /* - *附件下载 - */ - function attachAction(){ - - $uuid = $this->_request->getParam('uuid'); - - if(!empty($uuid)) - { - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - /* - $user = $auth->getIdentity(); - $userid = $user->id; - $sql = "select d.* from dataorder d - left join users u on u.id=d.userid - left join metadata m on m.uuid=d.uuid - where (d.status=5 and d.userid='$userid' and d.uuid='$uuid') or u.usertype='administrator'"; - $re= $this->db->query($sql); - $row=$re->fetch(); - if(!empty($row['uuid'])) - { - $this->messenger->addMessage('您没有权限下载该附件'); - $this->_redirect("/data"); - } - else - {*/ - //由于涉及多个文件下载,所以将附件添加到zip压缩文件再输出 - - $sql="select * from mdattach m left join attachments a on m.id=a.id where m.uuid='$uuid'"; - $re=$this->db->query($sql); - $atts = $re->fetchAll(); - - $zip = new ZipArchive(); - $url=Zend_Registry::get('upload')."tmp/attachments_$uuid.zip";//创建临时文件 - $opened=$zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); - if( $opened !== true ){ - die("cannot open {$url} for writing."); - } - - $updates = array(); //统计被下载的附件ID - - foreach ($atts as $k=>$v) - { - if (is_file(Zend_Registry::get('upload').$v['filename'])) { - $updates[]=$v['id']; - $zip->addFile(Zend_Registry::get('upload').$v['filename'],'/'.basename($v['filename'])); - } - } - $zip->close(); - - //更新统计 - $ids=join(',',$updates); - $sql = "update attachments set downtimes=downtimes+1 where id in ($ids)"; - @$this->db->exec($sql); - - - //输出下载 - $content=file_get_contents($url); - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $this->getResponse()->setHeader('Content-Type', 'application/octet-stream') - ->setHeader('Content-Disposition','attachment; filename="'.basename($url).'"') - ->setHeader('Content-Length', strlen($content)) - ->setHeader('Content-Type','application/force-download') - ->setHeader('Content-Type','application/download') - ->setHeader('Content-Type','application/zip') - ->setHeader('Content-Description','File Transfer') - ->setHeader('Content-Transfer-Encoding','binary') - ->setHeader('Expires',0) - ->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0') - ->setHeader('Pragma','public') - ->setBody($content); - // } - }//end if - else - { - $this->messenger->addMessage('您没有权限下载该附件'); - $this->_redirect("/data"); - }//未登陆 - }//end if - else - { - $this->messenger->addMessage('您没有权限下载该附件'); - $this->_redirect("/data"); - }//无权限 - - } - - /** * parse the wiki syntax used to render tables, code modified from mediawiki