Posted By

section31 on 07/08/08


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

SpinZ
wizard04
the_coder


Download File


 / Published in: PHP
 

Serves an external document for download as an HTTP attachment.

  1. // Serves an external document for download as an attachment.
  2. // example usage: download_file('whatever.wmv');
  3. function download_file($filename, $mimetype = 'application/octet-stream')
  4. {
  5. if (!file_exists($filename) || !is_readable($filename)) return false;
  6. $base = basename($filename);
  7. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  8. header("Content-Disposition: attachment; filename=$base");
  9. header("Content-Length: " . filesize($filename));
  10. header("Content-Type: $mimetype");
  11. readfile($filename);
  12. exit();
  13. }

Report this snippet  

You need to login to post a comment.