我有以下代码可以在WinRAR的Windows上正常工作,并且在Mac上工作正常.但是,出于某种原因,当您使用默认的Windows资源管理器打开它时,zip显示为空,当您右键单击并提取时,它表示它无效.当用winrar或mac打开同一个文件时,所有文件都在那里.有任何想法吗?

$passcode = $_GET['passcode'];

    $zip = new ZipArchive;
    $download = 'download_files_'.$passcode.'.zip';
    $zip->open($download, ZipArchive::CREATE);
    foreach (glob("../dashboard/uploads/".$passcode."/*.jpg") as $file) { /* Add appropriate path to read content of zip */
        $zip->addFile($file);
    }
    $zip->close();
    header('Content-Type: application/zip');
    header("Content-Disposition: attachment; filename = $download");
    header('Content-Length: ' . filesize($download));
    header("Location: $download");

解决方法:

您可以使用以下方法解决此问题.

foreach (glob("../dashboard/uploads/".$passcode."/*.jpg") as $file) { 
    $zip->addFile(realpath($file), pathinfo($file, PATHINFO_BASENAME));
}

我希望这可以帮助你.


标签: php, zip

相关文章推荐

添加新评论,含*的栏目为必填