From 5151cda7ee0bfcc6646d286d40bc88301d779b4c Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 28 Sep 2011 04:04:25 +0000 Subject: [PATCH] =?UTF-8?q?Ticket=20#189=20=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=8B=E8=BD=BD=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E5=92=8C=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DataController.php | 60 ++++++++++++++++++- .../views/scripts/data/attachments.phtml | 10 +++- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index b9eb09a5..4c6c3213 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -747,6 +747,7 @@ class Admin_DataController extends Zend_Controller_Action if(empty($msg['error'])) { $filename = $msg['db_path']; + $filesize = $msg['file_size']; $filedesc = $this->_request->getParam('filedesc'); $filetype = $this->_request->getParam('dir'); @@ -755,7 +756,7 @@ class Admin_DataController extends Zend_Controller_Action { $user = $auth->getIdentity(); $userid = $user->id; - $sql = "insert into attachments (filename,filetype,filedesc,userid) values ('$filename','$filetype','$filedesc','$userid')"; + $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize) values ('$filename','$filetype','$filedesc','$userid','$filesize')"; if($this->db->exec($sql)>0) { $this->messenger->addMessage('附件上传成功!'); @@ -880,9 +881,64 @@ class Admin_DataController extends Zend_Controller_Action } }//我的附件列表 + else if ($down>0) + { + + $sql = "select * from attachments where id='$down'"; + + $re = $this->db->query($sql); + + $row = $re->fetch(); + + $file = new files(); + + $fullPath = Zend_Registry::get('upload').$row['filename']; + + + // Parse Info / Get Extension + $fsize = filesize($fullPath); + $path_parts = pathinfo($fullPath); + $ext = strtolower($path_parts["extension"]); + + // Determine Content Type + switch ($ext) { + case "pdf": $ctype="application/pdf"; break; + case "exe": $ctype="application/octet-stream"; break; + case "zip": $ctype="application/zip"; break; + case "doc": $ctype="application/msword"; break; + case "xls": $ctype="application/vnd.ms-excel"; break; + case "ppt": $ctype="application/vnd.ms-powerpoint"; break; + case "gif": $ctype="image/gif"; break; + case "png": $ctype="image/png"; break; + case "jpeg": + case "jpg": $ctype="image/jpg"; break; + default: $ctype="application/force-download"; + } + + $content=file_get_contents($fullPath); + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'application/octet-stream') + ->setHeader('Content-Disposition','attachment; filename="'.basename($fullPath).'"') + ->setHeader('Content-Length', $fsize) + ->setHeader('Content-Type','application/force-download') + ->setHeader('Content-Type','application/download') + ->setHeader('Content-Type',$ctype) + ->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); + + $sql = "update attachments set downtimes=downtimes+1 where id='$down'"; + $this->db->exec($sql); + + }//附件下载 + else { - $sql="select * from attachments"; + $sql="select * from attachments order by id desc"; $re= $this->db->query($sql); $rows = $re->fetchAll(); diff --git a/application/admin/views/scripts/data/attachments.phtml b/application/admin/views/scripts/data/attachments.phtml index 508dd4ba..853c4c43 100644 --- a/application/admin/views/scripts/data/attachments.phtml +++ b/application/admin/views/scripts/data/attachments.phtml @@ -42,6 +42,8 @@ 描述 类型 + 大小 + 下载次数 上传时间 操作 @@ -56,11 +58,13 @@ if($item['filetype']=='file') echo '文件' ; if($item['filetype']=='media') echo '多媒体' ; ?> + + - 编辑 | - 删除 | - 下载 + 编辑 | + 删除 | + 下载