laravel 实现 zip 压缩图片并下载
扩展包:chumper/zipper
扩展包链接:https://github.com/Chumper/Zipper
假定:已经将要压缩下载的文件下载到本地,并该文件夹为test
<?php
use Chumper\Zipper\Zipper;
class ZipController extends Controller
{
public function downLoad()
{
$zipper = new Zipper();
//glob() 函数返回一个包含匹配指定模式的文件名或目录的数组。
$file_arr = glob(public_path('test'));
$result = $zipper->make(public_path($integral->title.'.zip'))
->folder('images')
->add($file_arr);
$result->close();
//删除指定文件夹 test
$this->delDirAndFile(public_path('test'),false);
//将二维码下载到本地 并删除该压缩包test.zip
return response()->download(public_path($integral->title.'.zip'))
->deleteFileAfterSend(true);
}
}