标签:upload epo down 压缩包 archive root ges isp ima
//批量下载图片
public function download_img_all(){
//图片数组
$res = array(
[0] = array(
‘ima_path‘=>‘/Uploads/1.png‘,
),
[1] = array(
‘ima_path‘=>‘/Uploads/2.png‘,
)
);
//创建压缩包的路径
$filename = $_SERVER[‘DOCUMENT_ROOT‘].‘/Uploads/Dwonload.zip‘;
$zip = new \ZipArchive;
$zip->open($filename,$zip::CREATE);
//往压缩包内添加目录
$zip->addEmptyDir(‘images‘);
foreach ($res as $value) {
$fileData = file_get_contents( $_SERVER[‘DOCUMENT_ROOT‘].$value[‘img_path‘]);
if ($fileData) {
$add = $zip->addFromString(‘images/‘.$value[‘img_path‘].‘.jpg‘, $fileData);
}
}
$zip->close();
//打开文件
//下载文件
ob_end_clean();
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header(‘Content-Type: application/zip‘);
header(‘Content-Disposition: attachment; filename=‘.time().‘.zip‘);
header(‘Content-Length: ‘.filesize($filename));
error_reporting(0);
readfile($filename);
flush();
ob_flush();
}
download_img_all();
//大概就是这样子
标签:upload epo down 压缩包 archive root ges isp ima
原文地址:http://www.cnblogs.com/tojiek/p/6073231.html