代码如下:
/**
* 强制文件下载
* by http://www.jbxue.com
*/
function downloadFile($file){
$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();
}
?>
有关php header信息的相关内容,请参考:php头部文件(header)信息。
您可能感兴趣的文章:
php强制文件下载(避免文件或图片直接在浏览器中打开)
php 强制文件下载的一段代码
php强制下载指定类型文件的代码
php 强制文件下载的实现代码一例
php强制性文件下载的函数