// 批量下载文件
public function LW_download()
{
header("Content-type: text/html; charset=utf-8");
$moduleid=I("get.position");
$Result=D('resume')->where(array('moduleid'=>$moduleid))->field('filename')->select();
$array = array_column($Result,'filename');
$tmpFile = tempnam('/Upload/temp', ''); //临时文件
$zip = new \ZipArchive(); //php内置的压缩类
$aa=$zip->open($tmpFile, \ZipArchive::CREATE);
foreach ($array as $value) {
$file=iconv("utf-8","gb2312",$url.$value); //,防止中文乱码 $url是存放目录
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$fileContent = curl_exec($ch);
curl_close($ch);
$zip->addFromString(basename($file), $fileContent); //将文件循环压缩到压缩包
}
$zip->close();
header('Content-Type: application/zip');
header ( "Content-Transfer-Encoding: Binary" );
header("Content-disposition: attachment; filename='file.zip'");
header('Content-Length: ' . filesize($tmpFile));
ob_end_clean();
readfile($tmpFile);
unlink($tmpFile);
}
php打包压缩文件并下载
猜你喜欢
转载自blog.csdn.net/weixin_41965172/article/details/102909797
今日推荐
周排行