We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

tylerhall on 11/27/06


Tagged

http file download save


Versions (?)


Who likes this?

17 people have marked this snippet as a favorite

luman
damarev
blakeb
dmarten
jacksont123
Phoenix
hudge
vali29
skywalker
JimiJay
SpinZ
mb
srpsco
haozi
mrjthethird
tikitakfire
sumandahal


Download File


Published in: PHP 


Via ActiveCollab

  1. function download_contents($content, $type, $name, $size, $force_download = false) {
  2. if(connection_status() != 0) return false; // check connection
  3.  
  4. if($force_download) {
  5. header("Cache-Control: public");
  6. } else {
  7. header("Cache-Control: no-store, no-cache, must-revalidate");
  8. header("Cache-Control: post-check=0, pre-check=0", false);
  9. header("Pragma: no-cache");
  10. } // if
  11. header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
  12. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  13. header("Content-Type: $type");
  14. header("Content-Length: " . (string) $size);
  15.  
  16. // Prepare disposition
  17. $disposition = $force_download ? 'attachment' : 'inline';
  18. header("Content-Disposition: $disposition; filename=\"" . $name) . "\"";
  19. header("Content-Transfer-Encoding: binary");
  20. print $content;
  21.  
  22. return((connection_status() == 0) && !connection_aborted());
  23. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: srpsco on May 7, 2008

check for pd

Posted By: srpsco on May 7, 2008

check for pd

Posted By: srpsco on May 7, 2008

check for pd

Posted By: srpsco on May 7, 2008

check for pd

You need to login to post a comment.