shosei

Download file

Mar 11th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  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.   }
Add Comment
Please, Sign In to add comment