欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php通过修改header强制图片下载的代码

程序员文章站 2022-04-07 09:10:54
...
  1. unction downloadFile($file){
  2. $file_name = $file;
  3. $mime = 'application/force-download';
  4. header('Pragma: public'); // required
  5. header('Expires: 0'); // no cache
  6. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  7. header('Cache-Control: private',false);
  8. header('Content-Type: '.$mime);
  9. header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
  10. header('Content-Transfer-Encoding: binary');
  11. header('Connection: close');
  12. readfile($file_name); // push it out
  13. exit();
  14. }
复制代码

php, header