使用php下载多个文件作为zip文件夹

问题描述:

我想让我的用户选择列出的任何类型的文件,并将它们作为zip文件夹下载。这些文件可能是.doc,.jpeg,.ppt等使用php下载多个文件作为zip文件夹

你可以看看ZipArchive,你就可以创建拉链并让用户下载它。

Cletus提供了一个非常好的答案there。我谦恭地复制到这里他的样本

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

并流呢:

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

确定ragez我会给予一个尝试 – 2009-11-19 05:24:22

+0

类ZipFile中没有找到,我得到这个错误 – 2009-11-19 05:30:31

+0

@netcoder:谢谢你的编辑。 – RageZ 2011-02-07 02:35:30