Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 标头-下载的Gzip不是Gzip格式,在服务器上正确_Php_Download_Gzip - Fatal编程技术网

Php 标头-下载的Gzip不是Gzip格式,在服务器上正确

Php 标头-下载的Gzip不是Gzip格式,在服务器上正确,php,download,gzip,Php,Download,Gzip,我正在尝试创建、下载然后删除一个gzip文件 在服务器上创建的文件是正确的。我可以通过直接链接下载,文件在本地正确解压缩 如果我使用header(),文件将不会解压缩,并给出一个错误“Not In Gzip格式”。似乎我必须使用header(),才能取消链接() 守则的要点是: # This creates the gz file correctly.. $tar = 'meta-info.tar'; $gz = $tar.'.gz'; $p = new PharData($tar); $p-&

我正在尝试创建、下载然后删除一个gzip文件

在服务器上创建的文件是正确的。我可以通过直接链接下载,文件在本地正确解压缩

如果我使用header(),文件将不会解压缩,并给出一个错误“Not In Gzip格式”。似乎我必须使用header(),才能取消链接()

守则的要点是:

# This creates the gz file correctly..
$tar = 'meta-info.tar';
$gz = $tar.'.gz';
$p = new PharData($tar);
$p->compress(Phar::GZ)->buildFromDirectory('../');

# This creates the dialog then removes the file correctly..
header('Content-Type:'.mime_content_type($gz));
header('Content-Length:'.filesize($gz));
header("Content-Disposition:attachment;filename=$gz");
flush();
readfile($gz);
unlink($gz);

# ...but the downloaded file is not correct.
奇怪的是,“zip”文件可以正确下载和解压缩

我已经找遍了stackoverflow,尝试了很多方法,但都不管用。。有什么想法吗


提前谢谢

问题是已经发送了标题信息

使用ob_end_clean()修复了它(页面的结构无法更改)


问题是已经发送了标题信息

使用ob_end_clean()修复了它(页面的结构无法更改)


那么实际发送的是什么内容类型的头呢?使用浏览器开发控制台检查您得到的响应。您无法看到什么?如果您下载了一个文件,那么您肯定执行了一个请求,这肯定会显示在开发控制台中。您知道如何打开它并使用其中的“网络”选项卡吗?AFAICS
application/x-gzip
不属于通常支持的官方mime类型……可能是http服务器的激活压缩模块拦截?听起来很奇怪,不过…你看过那些数据了吗?这是网页的开始:
那么实际发送的是什么内容类型的标题?使用浏览器开发控制台检查您得到的响应。您无法看到什么?如果您下载了一个文件,那么您肯定执行了一个请求,这肯定会显示在开发控制台中。您知道如何打开它并使用其中的“网络”选项卡吗?AFAICS
application/x-gzip
不属于通常支持的官方mime类型……可能是http服务器的激活压缩模块拦截?听起来很奇怪,不过…你看过那些数据了吗?这是一个网页的开始:
在我的例子中,这段代码工作得非常好ob_end_clean();标题(“内容类型:应用程序/tar+gzip”);标题('Content-Disposition:attachment;filename=“.”.$filename.'”);readfile(“.$filename.”);在我的例子中,这段代码工作得非常好ob_end_clean();标题(“内容类型:应用程序/tar+gzip”);标题('Content-Disposition:attachment;filename=“.”.$filename.'”);readfile(“.$filename.”);
ob_end_clean();
header("Content-Disposition:attachment;filename=$gz");
header('Content-Type:application/x-gzip');
header('Content-Length:'.filesize($gz));
flush();
readfile($gz);
unlink($gz);