Posted By

flatearthcomms on 01/20/09


Tagged

file download


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

xtheonex
umang_nine


Force download


 / Published in: PHP
 

  1. <?php
  2. //Set this to the base of where files
  3. //can be downloaded from for security measures.
  4. $basedir = "D:/wwwroot/";
  5. if(!$_GET['file']) {
  6. print "Sorry that file does not exist";
  7. exit;
  8. }
  9. elseif(!file_exists($basedir.$_GET['file'])) {
  10. print "Sorry that file does not exist";
  11. exit;
  12. }
  13. else {
  14. header("Content-Type: octet/stream");
  15. header("Content-Disposition: attachment; filename=\"".$_GET['file']."\"");
  16. $fp = fopen($basedir.$_GET['file'], "r");
  17. $data = fread($fp, filesize($basedir.$_GET['file']));
  18. fclose($fp);
  19. print $data;
  20. }
  21. ?>

Report this snippet  

You need to login to post a comment.