Posted By

level09 on 08/18/09


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

luman
umang_nine
ReeceMarsland


Force File Download


 / Published in: PHP
 

  1. function force_download($file)
  2. {
  3. if ((isset($file))&&(file_exists($file))) {
  4. header("Content-length: ".filesize($file));
  5. header('Content-Type: application/octet-stream');
  6. header('Content-Disposition: attachment; filename="' . $file . '"');
  7. readfile("$file");
  8. } else {
  9. echo "No file selected";
  10. }
  11. }

Report this snippet  

You need to login to post a comment.