Posted By

macodev on 04/07/17


Tagged

file headers download


Versions (?)

Download file headers


 / Published in: PHP
 

Set headers for file download

  1. function download_headers($filename)
  2. {
  3. // disable caching
  4. $now = gmdate("D, d M Y H:i:s");
  5. header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
  6. header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
  7. header("Last-Modified: {$now} GMT");
  8.  
  9. // force download
  10. header("Content-Type: application/force-download");
  11. header("Content-Type: application/octet-stream");
  12. header("Content-Type: application/download");
  13.  
  14. // disposition / encoding on response body
  15. header("Content-Disposition: attachment;filename={$filename}");
  16. header("Content-Transfer-Encoding: binary");
  17. }

Report this snippet  

You need to login to post a comment.