Posted By

luman on 01/05/09


Tagged

file download


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

will_00
fackz
umang_nine
vali29


Force downloading a file


 / Published in: PHP
 

  1. <?php
  2. if($_GET){
  3. if($_GET['file']) {
  4. $filename = $_GET['file'];
  5. $download_path = "files/";
  6. }
  7.  
  8. if(eregi("\.\.", $filename)) die("I'm sorry, you may not download that file.");
  9. $file = str_replace("..", "", $filename);
  10. if(eregi("\.ht.+", $filename)) die("I'm sorry, you may not download that file.");
  11. $file = "$download_path$file";
  12. if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
  13. $type = filetype($file);
  14. $today = date("F j, Y, g:i a");
  15. $time = time();
  16.  
  17. header("Content-type: $type");
  18. header("Content-Disposition: attachment;filename=$filename");
  19. header("Content-Transfer-Encoding: binary");
  20. header("Cache-Control: ");
  21. header("Pragma: ");
  22. readfile($file);
  23. }
  24. ?>

Report this snippet  

You need to login to post a comment.