【问题标题】:Php download file corruptionphp下载文件损坏
【发布时间】:2015-07-16 05:50:55
【问题描述】:

我正在尝试使用以下内容下载 .tgz 文件:

$file = '/var/www/upload/myfile.tgz';

if (file_exists($file))
{
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}

问题是当我试图提取下载的文件时 tar 给我以下错误:

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

注意:尝试提取原始文件时不会出现此错误。

【问题讨论】:

  • 存档是 tar,而不是 GZip 存档。
  • 解压不带 z 的 tar,仅用于 gzip(压缩):
  • @JunaidAhmed ,@saty Im 使用 tar xf myfile.tgz ,它适用于原始版本,但不适用于下载
  • 检查两者的确切文件大小,或者如果您有工具,请比较文件

标签: php


【解决方案1】:

当我将代码移动到单独的 .php 文件时它起作用了

【讨论】:

  • 似乎在您的旧 php 文件中您回显了一些字符,例如在标题和退出调用前面的开头左右的空格。
猜你喜欢
  • 1970-01-01
  • 2014-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-23
  • 2012-12-05
  • 1970-01-01
相关资源
最近更新 更多