如何用PHP修改HTTP头实现图片强制下载?
- 内容介绍
- 文章标签
- 相关推荐
本文共计123个文字,预计阅读时间需要1分钟。
javascriptfunction downloadFile($file) { $file_name=$file; $mime='application/force-download'; header('Pragma: public'); // 必须使用单引号,因为双引号中不能包含双引号 header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Type: ' + $mime); header('Content-Disposition: attachment; filename=' . basename($file_name) . ''); readfile($file_name);}
unction 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(); }
本文共计123个文字,预计阅读时间需要1分钟。
javascriptfunction downloadFile($file) { $file_name=$file; $mime='application/force-download'; header('Pragma: public'); // 必须使用单引号,因为双引号中不能包含双引号 header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Type: ' + $mime); header('Content-Disposition: attachment; filename=' . basename($file_name) . ''); readfile($file_name);}
unction 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(); }

