php强制下载类型的实现代码
前端之家收集整理的这篇文章主要介绍了
php强制下载类型的实现代码,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<div class="codetitle"><a style="CURSOR: pointer" data="83054" class="copybut" id="copybut83054" onclick="doCopy('code83054')"> 代码如下:
<div class="codebody" id="code83054">
function downloadFile($file){
/
Coded by Alessio Delmonti/
$file_name = $file;
$mime = 'application/force-download';
header('Pragma: public'); //
required header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile($file_name); // push it out
exit();
}