public function bulkDownload(){
$ids=I("ids");
$images = M('contract_mouldcrm')->where(['id'=>array('in',$ids)])->getField('url',true);
$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);
//销毁服务器zip文件
@unlink($filename);
}
<input id="bt1" class="btn btn-primary" value="批量下载" type="button" onClick="grant_salary()">
<script>
function grant_salary(job_id,member_id,enterprise_id){
var id_array=new Array();
$('input[id="ids"]:checked').each(function(){
id_array.push($(this).val());
});
alert(id_array);
window.location.href = "http://crm.com/Crm/Contract/bulkDownload?ids="+id_array;
}
</script>
网友评论