We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

coggla on 01/20/08


Tagged

file headers download content-disposition


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

uisluu
srpsco


Force a file download


Published in: PHP 


  1. $file = $_GET["file"];
  2. $download = "http://www.ssn.flinders.edu.au/".$file;
  3.  
  4. if(ini_get('zlib.output_compression')) {
  5. ini_set('zlib.output_compression', 'Off');
  6. }
  7.  
  8. header("Pragma: public");
  9. header("Expires: 0");
  10. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  11. header("Cache-Control: private",false);
  12. header("Content-type: application/pdf");
  13. header("Content-Disposition: attachment; filename=".basename($download).";" );
  14. readfile("$download");

Report this snippet 

You need to login to post a comment.