<?php
$fileList = array(
  "../uploads/04e0f6f1708a8f6afe229fb25a80336d.jpg",
  "../uploads/0f33737ccc1cd357e8f03b5008071ff8.jpg"
);
$filename = "test.zip";
$zip = new ZipArchive();
$zip->open($filename,ZipArchive::CREATE);  //打开压缩包
foreach($fileList as $file){
  $zip->addFile($file,basename($file));  //向压缩包中添加文件
}
$zip->close(); //关闭压缩包
if(downloadFile($filename,$filename)){
    @unlink($filename);
}



function downloadFile($filePath,$showName) {
    if (is_file($filePath)) {
        //打开文件
        $file = fopen($filePath,"rb");
        //返回的文件类型
        Header("Content-type: application/octet-stream");
        //按照字节大小返回
        Header("Accept-Ranges: bytes");
        //返回文件的大小b
        Header("Accept-Length: ".filesize($filePath));
        //这里设置客户端的弹出对话框显示的文件名
        Header("Content-Disposition: attachment; filename=".$showName);
        //一次性将数据传输给客户端
        //echo fread($file, filesize($filePath));
        //一次只传输1024个字节的数据给客户端
        //向客户端回送数据
        $buffer=1024;//
        //判断文件是否读完
        while (!feof($file)) {
            //将文件读入内存
            $file_data = fread($file, $buffer);
            //每次向客户端回送1024个字节的数据
            echo $file_data;
        }
        return true;
    }else {
        return false;
    }
}