求PHP打包下载图片的代码
本文介绍了求PHP打包下载图片的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如题,
注意:不是做图片采集,图片已在服务器上,需求是用户勾选了几张图片后,下载到用户的电脑上,单个没问题,多个不知道如何弄
解决方案
$zip = new \ZipArchive;
//压缩文件名
$filename = 'download.zip';
//新建zip压缩包
$zip->open($filename,\ZipArchive::OVERWRITE);
//把图片一张一张加进去压缩
foreach ($images as $key => $value) {
$zip->addFile($value);
}
//打包zip
$zip->close();
//可以直接重定向下载
header('Location:'.$filename);
//或者输出下载
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.basename($filename)); //文件名
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($filename)); //告诉浏览器,文件大小
readfile($filename);
这篇关于求PHP打包下载图片的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文