我要做的是遍历链接列表并将它们全部压缩到同一目录中。这些文件包括图像,PDF,音频和视频。问题是某些文件很大,我收到以下错误:
FatalErrorException: Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 46512453 bytes)...
这就是我现在所拥有的:
$zip = new ZipArchive();
$tmp_file = tempnam('.','');
$zip->open($tmp_file, ZipArchive::CREATE);
foreach($mediaFiles as $file){
$downloadFile = file_get_contents($file);
$zip->addFromString(basename($file), $downloadFile);
}
$zip->close();
header('Content-disposition: attachment; filename=download.zip');
header('Content-type: application/zip');
readfile($tmp_file);
答案 0 :(得分:0)
检查这个库,它允许创建zip文件并将它们作为流返回:
http://www.phpclasses.org/package/6110-PHP-Create-archives-of-compressed-files-in-ZIP-format.html