Force File Download


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

Provide files to the user by forcing them to download.


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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.