为什么PHP的gzuncompress()函数会出错? [英] Why PHP's gzuncompress() function can go wrong?

查看:365
本文介绍了为什么PHP的gzuncompress()函数会出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP具有其自己的功能,可用于gzip存档.我写了以下代码:

PHP has its own function to work with gzip archives. I wrote the following code:

error_reporting(E_ALL);
$f = file_get_contents('http://spiderbites.nytimes.com/sitemaps/www.nytimes.com/sitemap.xml.gz');
echo $f;
$f = gzuncompress($f);
echo "<hr>";
echo $f;

First echo通常会输出带有适当头的压缩文件(至少前两个字节是正确的).如果要使用浏览器下载该文件,则可以轻松地将其解压缩.

First echo normally outputs the compressed file with proper header (at least first two bytes are correct). If I'd download this file with my browser I can unzip it easily.

但是gzuncompress抛出了Warning: gzuncompress(): data error in /home/path/to/script.php on line 5

However gzuncompress thrown Warning: gzuncompress(): data error in /home/path/to/script.php on line 5

有人能指出我正确的方向来解决这个问题吗?

Can anyone point me to the right direction to solve this problem?

phpinfo()输出的一部分

The part of phpinfo() output

推荐答案

或者您可以使用正确的解压缩功能 .

Or you could just use the right decompression function, gzdecode().

这篇关于为什么PHP的gzuncompress()函数会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆