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

Posted By: shahzadanwar on July 18, 2009

mere pass ek file hai jis ka format "php" hai or wo kisi be format mein open nahein ho rahi kindly mujay is file ko support kerne wala software de dein tan ke mein apna kam ker sakon

Thanks,

From: [email protected]

You need to login to post a comment.