review中修改了下载时的用户判断和输出下载的目标窗口
This commit is contained in:
parent
32b30a6126
commit
5684a7ca1c
|
@ -410,7 +410,7 @@ class ReviewController extends Zend_Controller_Action
|
||||||
}
|
}
|
||||||
$list[] = '
|
$list[] = '
|
||||||
<li>'.$v['realname'].' ('.$v['filesize'].')
|
<li>'.$v['realname'].' ('.$v['filesize'].')
|
||||||
<span><a href="/review/downatt/id/'.$v['id'].'">下载</a></span>
|
<span><a href="/review/downatt/id/'.$v['id'].'" target="_blank">下载</a></span>
|
||||||
</li>
|
</li>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
|
@ -432,47 +432,61 @@ class ReviewController extends Zend_Controller_Action
|
||||||
|
|
||||||
$id = $this->_request->getParam('id');
|
$id = $this->_request->getParam('id');
|
||||||
|
|
||||||
$sql = "select * from attachments where id='$id'";
|
$auth = Zend_Auth::getInstance();
|
||||||
|
if($auth->hasIdentity())
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
$sql = "select * from attachments where id='$id'";
|
||||||
|
|
||||||
$re = $this->db->query($sql);
|
$re = $this->db->query($sql);
|
||||||
|
|
||||||
$row = $re->fetch();
|
$row = $re->fetch();
|
||||||
|
|
||||||
$fullPath = $this->view->config->upload.$row['filename'];
|
$fullPath = $this->view->config->upload.$row['filename'];
|
||||||
|
|
||||||
$fsize = filesize($fullPath);
|
$fsize = filesize($fullPath);
|
||||||
$path_parts = pathinfo($fullPath);
|
$path_parts = pathinfo($fullPath);
|
||||||
$ext = strtolower($path_parts["extension"]);
|
$ext = strtolower($path_parts["extension"]);
|
||||||
|
|
||||||
switch ($ext) {
|
switch ($ext) {
|
||||||
case "pdf": $ctype="application/pdf"; break;
|
case "pdf": $ctype="application/pdf"; break;
|
||||||
case "exe": $ctype="application/octet-stream"; break;
|
case "exe": $ctype="application/octet-stream"; break;
|
||||||
case "zip": $ctype="application/zip"; break;
|
case "zip": $ctype="application/zip"; break;
|
||||||
case "doc": $ctype="application/msword"; break;
|
case "doc": $ctype="application/msword"; break;
|
||||||
case "xls": $ctype="application/vnd.ms-excel"; break;
|
case "xls": $ctype="application/vnd.ms-excel"; break;
|
||||||
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
|
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
|
||||||
case "gif": $ctype="image/gif"; break;
|
case "gif": $ctype="image/gif"; break;
|
||||||
case "png": $ctype="image/png"; break;
|
case "png": $ctype="image/png"; break;
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
case "jpg": $ctype="image/jpg"; break;
|
case "jpg": $ctype="image/jpg"; break;
|
||||||
default: $ctype="application/force-download";
|
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="'.$row['realname'].'"')
|
||||||
|
->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 = $id";
|
||||||
|
@$this->db->exec($sql);
|
||||||
|
}catch(Exception $e){
|
||||||
|
echo '文件读取出错,请稍后重试';
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
echo '读取用户信息出错,请先登录再下载附件';
|
||||||
}
|
}
|
||||||
|
|
||||||
$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);
|
|
||||||
}// downattAction 下载附件
|
}// downattAction 下载附件
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue