Download file headers


/ Published in: PHP
Save to your folder(s)

Set headers for file download


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.