【问题标题】:PHP ZipArchive - Downloaded file says i'ts empty but it's notPHP ZipArchive - 下载的文件说我是空的,但它不是
【发布时间】:2019-01-09 22:50:18
【问题描述】:

我有下面的代码创建一个 ZIP 文件,添加一个文件,然后下载到我的电脑。

$zip = new ZipArchive();
if ($zip->open('order_sheets.zip', ZipArchive::CREATE) === TRUE){
    $zip->addFile($pdfFilePath);
}
$zip->close();

$file_url = 'order_sheets.zip';
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$file_url);
header('Content-Length: ' . filesize($file_url));
readfile($file_url);

一切正常,但问题是,当打开下载的 ZIP 时,它说这个文件夹是空的,而实际上不是。如果我右键单击并点击“在此处提取”,内容就会出来。

有人知道这是为什么吗?

【问题讨论】:

    标签: php


    【解决方案1】:

    问题在于 Windows 的 zip 实用程序,它使用 IBM850 编码,导致它误解存档中内部文件名中的某些字符,包括文件中的_(下划线)。

    在此处查看答案: PHP ZipArchive Corrupt in Windows

    在此处的 PHP 手册用户注释中进行了解释:http://php.net/manual/en/ziparchive.addfile.php#95725

    【讨论】:

      猜你喜欢
      • 2019-08-02
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多