Posted By

hasantayyar on 08/18/09


Tagged

php download


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

hasantayyar
umang_nine
aleksanderek


Force download a file


 / Published in: PHP
 

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

Report this snippet  

You need to login to post a comment.