【问题标题】:Download multiple files with php ZipArchive使用 php ZipArchive 下载多个文件
【发布时间】:2020-05-16 05:59:26
【问题描述】:

我尝试使用 ZipArchive 下载多个文件,此代码推荐in this post

$files = array('readme.txt', 'test.html', 'image.gif');
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();

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

但它没有用。是的,它确实创建了一个 zip 文件,但是当我尝试提取它时,我收到消息说存档不可读并且存档可能无效或者其目录可能被加密。怎么了?

【问题讨论】:

  • 你能检查$zip->open的返回值吗? .. 见docs.
  • 返回值为真
  • 不,我解决了问题是最后 4 行。而不是我使用 header('location: /' . $zipname);效果很好!
  • 您应该将此作为答案发布并接受它,以便其他人可以看到您的问题已解决,尤其是如果您自己解决了问题:)

标签: php zip


【解决方案1】:

我解决了问题是最后 4 行。而不是我使用 header('location: /' . $zipname);效果很好!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    • 2023-04-07
    • 2012-03-04
    • 1970-01-01
    • 2010-12-17
    • 2015-07-05
    相关资源
    最近更新 更多