shosei

Download File

Mar 11th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2.  
  3. $filename = $_GET['filename'];
  4.  
  5. // Modify this line to indicate the location of the files you want people to be able to download
  6. // This path must not contain a trailing slash.  ie.  /temp/files/download
  7. $download_path = "ficheros/";
  8.    
  9. // Make sure we can't download files above the current directory location.
  10. if(eregi("\.\.", $filename)) die("I'm sorry, you may not download that file.");
  11. $file = str_replace("..", "", $filename);
  12.    
  13. // Make sure we can't download .ht control files.
  14. if(eregi("\.ht.+", $filename)) die("I'm sorry, you may not download that file.");
  15.    
  16. // Combine the download path and the filename to create the full path to the file.
  17. $file = "$download_path$file";
  18.    
  19. // Test to ensure that the file exists.
  20. if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
  21.    
  22. // Extract the type of file which will be sent to the browser as a header
  23. $type = filetype($file);
  24.  
  25. // Get a date and timestamp
  26. $today = date("F j, Y, g:i a");
  27. $time = time();
  28.  
  29. // Send file headers
  30. header("Content-type: $type");
  31. header("Content-Disposition: attachment;filename=$filename");
  32. header("Content-Transfer-Encoding: binary");
  33. header('Pragma: no-cache');
  34. header('Expires: 0');
  35. // Send the file contents.
  36. set_time_limit(0);
  37. readfile($file);
  38.  
  39. ?>
Add Comment
Please, Sign In to add comment