Posted By

tonic on 09/29/08


Tagged

php header download attachment force


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

luman


Force download


 / Published in: PHP
 

  1. // Require GET variables: $nombre, $path. Ej: ?nombre=test1.pdf&path=/folder/
  2.  
  3. $filename=$nombre;
  4. $filepath=$path.$nombre;
  5. $filesize=filesize($filepath);
  6. header("Pragma: public");
  7. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  8. header("Content-Length: ".$filesize);
  9. header("Content-Disposition: attachment; filename=$filename");
  10. header("Content-Transfer-Encoding: binary");
  11.  
  12. //$fp = fopen($filepath, 'rb');
  13. //$file_buffer = fread($fp, $filesize);
  14. //fclose ($fp);
  15. //print $file_buffer;
  16.  
  17. readfile($filepath);
  18. exit();

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: MMDeveloper on September 29, 2008

just an fyi. Might want to sanitize what is downloaded before password files and other non-public files are downloaded.

You need to login to post a comment.