Posted By

Mosaic on 03/10/11


Tagged

header type download content force


Versions (?)

[php] Force Download file


 / Published in: PHP
 

URL: www.tecnocrazia.com

Simple force download crossbrowser

  1. function downloadFile($file){
  2. /*Coded by Alessio Delmonti*/
  3. $file_name = $file;
  4. $mime = 'application/force-download';
  5. header('Pragma: public'); // required
  6. header('Expires: 0'); // no cache
  7. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  8. header('Cache-Control: private',false);
  9. header('Content-Type: '.$mime);
  10. header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
  11. header('Content-Transfer-Encoding: binary');
  12. header('Connection: close');
  13. readfile($file_name); // push it out
  14. exit();
  15. }

Report this snippet  

You need to login to post a comment.