php技术博客
让天下没有搞不定的bug~

php的强制下载方法

分享一下php的强制下载方法,可以进行封装成类,拿来直接可以用:

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

技术分享,技术交流,小涛与您共同成长……

赞(0)
未经允许不得转载:PHP技术博客 » php的强制下载方法