[php] Force Download file


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

Simple force download crossbrowser


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

URL: www.tecnocrazia.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.