使用php将多个文件下载为zip文件夹 [英] Download multiple files as a zip folder using php
本文介绍了使用php将多个文件下载为zip文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让我的用户选择列出的任何类型的文件,并将它们设置为zip文件夹并下载.文件可以是.doc,.jpeg,.ppt等
I want to make my user select any type of files listed and make them as a zip folder and download it. The files may be .doc,.jpeg,.ppt, etc
推荐答案
you can take a look at ZipArchive
, you would be able to create zips with that and let the user download it.
Cletus提供了一个非常好的答案,有.我谦虚地在这里复制他的样品
Cletus provide a really good answer there. I humbly copy his sample here
$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);
这篇关于使用php将多个文件下载为zip文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文