Force File Download


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.