凌的博客

您现在的位置是: 首页 > 学无止境 > PHP > 

PHP

PHP 生成gz压缩文件

2015-01-29 PHP 1065
//生成.gz function gz($file,$content){ // Name of the gz file we are creating $gzfile = $file.\".gz\"; // Open the gz file (w9 is the highest compression) $fp = gzopen ($gzfile, \'w9\');
//生成.gz
function gz($file,$content){
 
  // Name of the gz file we are creating
  $gzfile = $file.".gz";
   
  // Open the gz file (w9 is the highest compression)
  $fp = gzopen ($gzfile, 'w9');
   
  // Compress the file
  gzwrite ($fp,$content);
   
  // Close the gz file and we are done
  gzclose($fp);      
 
  if(file_exists($gzfile)){
       
      return true;
  }
}
//读取并下载
  $path = ROOT_DIR.$url;
  $filename = 'q_api.xml'; 
 
  gz($path.$filename,$xml);
 
  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
  header("Cache-Control: no-cache, must-revalidate");
  header("Pragma: no-cache");   
  header("Content-Type: application/force-download");           
  header("Content-type: application/x-gzip");
  header("Content-Disposition: attachment; filename=".$filename.'.gz'); 
  header("Content-Description: PHP3 Generated Data");
   
  readfile($path.$filename.".gz");


文章评论

0条评论