Posted By

paulgrenwood on 09/23/09


Tagged

php download


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

huynguye


Force File Download


 / Published in: PHP
 

Provide files to the user by forcing them to download.

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

Report this snippet  

You need to login to post a comment.