Ticket #189 增加了附件下载功能

增加了下载次数和文件大小的统计
This commit is contained in:
Li Jianxuan 2011-09-28 04:04:25 +00:00
parent a638770e96
commit 5151cda7ee
2 changed files with 65 additions and 5 deletions

View File

@ -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();

View File

@ -42,6 +42,8 @@
<thead><tr>
<th width='300'>描述</th>
<th width='100'>类型</th>
<th width='100'>大小</th>
<th width='100'>下载次数</th>
<th width='100'>上传时间</th>
<th width="150">操作</th>
</tr></thead>
@ -56,11 +58,13 @@
if($item['filetype']=='file') echo '文件' ;
if($item['filetype']=='media') echo '多媒体' ;
?></td>
<td><?php if($item['filesize']<1048576) echo round(($item['filesize']/1024),2).'KB'; else echo round(($item['filesize']/1024/1024),2).'MB'; ?></td>
<td><?= $item['downtimes']; ?></td>
<td><?= date('Y-m-d',strtotime($item['ts_created'])); ?></td>
<td>
<a href="/admin/data/attachments/edit/<?= $item['id']; ?>?">编辑</a> |
<a href="/admin/data/attachments/delete/<?= $item['id']; ?>?" onclick="return confirm('是否确定删除该附件?')">删除</a> |
<a href="/admin/data/attachments/down/<?= $item['id']; ?>?">下载</a>
<a href="/admin/data/attachments/edit/<?= $item['id']; ?>">编辑</a> |
<a href="/admin/data/attachments/delete/<?= $item['id']; ?>" onclick="return confirm('是否确定删除该附件?')">删除</a> |
<a href="/admin/data/attachments/down/<?= $item['id']; ?>">下载</a>
</td>
</tr>
<?php endforeach; ?>