dongzuoyue6556
2009-03-03 06:26
浏览 62

如何使用PHP提供gzip xml文件供下载

I have a PHP script that creates an xml file from the db. I would like to have the script create the xml data and immediately make a .gzip file available for download. Can you please give me some ideas?

Thanks!

图片转代码服务由CSDN问答提供 功能建议

我有一个PHP脚本,可以从db创建一个xml文件。 我想让脚本创建xml数据并立即生成.gzip文件供下载。 你能给我一些想法吗?

谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanlu7223 2009-03-03 06:31
    已采纳

    You can easily apply gzip compression with the gzencode function.

    <?
    header("Content-Disposition: attachment; filename=yourFile.xml.gz");
    header("Content-type: application/x-gzip");
    
    echo gzencode($xmlToCompress);
    
    点赞 打赏 评论
  • dongyanhu5628 2009-03-03 06:33

    If you don't have the gzip module available,

    <?php
    
      system('gzip filename.xml');
    
    ?>
    
    点赞 打赏 评论
  • dpgkg42484 2009-03-03 06:44

    Something like this?

    <?php
     header('Content-type: application/x-gzip');
     header('Content-Disposition: attachment; filename="downloaded.gz"');
     $data = implode("", file('somefile.xml'));
     print( gzencode($data, 9) ); //9 is the level of compression
    ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题