array(2) {
[0] => array(2) {
["img"] => string(111) "/Uploads/Staff/绍兴/测试/1626231191SDoQId.jpg,/Uploads/Staff/绍兴/测试/1626231191ikHoYb.jpg"
["k"] => string(6) "测试"
}
[1] => array(2) {
["img"] => string(111) "/Uploads/Staff/绍兴/测试/1626231191SDoQId.jpg,/Uploads/Staff/绍兴/测试/1626231191ikHoYb.jpg"
["k"] => string(7) "测试3"
}
}
string(30) "浙江"
private function downZip($imgs, $name){
header('content-type:image/jpg');
$filename = './tmp.zip';
$zip = new \ZipArchive();
$zip->open($filename, \ZipArchive::OVERWRITE | \ZIPARCHIVE::CREATE | \ZIPARCHIVE::CM_STORE);
foreach ($imgs as $key=>$vo) {
$fileData = file_get_contents(dirname($_SERVER['SCRIPT_FILENAME']).$vo['img']);
$temp = explode('.', $vo['img']);
$ext = $temp[count($temp)-1];
if ($fileData) {
$zip->addFromString($vo['k']. '.' . $ext, $fileData);
}
}
$zip->close();
$file = fopen($filename, "r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($filename));
Header("Content-Disposition: attachment; filename=$name.zip");
$buffer = 1024;
while (!feof($file)) {
$file_data = fread($file, $buffer);
echo $file_data;
}
fclose($file);
unlink($filename);
}
private function downimgsZip($imgs, $name){
header('content-type:image/jpg');
$filename = './tmp.zip';
$zip = new \ZipArchive();
$zip->open($filename, \ZipArchive::OVERWRITE | \ZIPARCHIVE::CREATE | \ZIPARCHIVE::CM_STORE);
foreach ($imgs as $key => $value){
$imgs[$key]['img'] = explode(',',$value['img']);
}
foreach ($imgs as $key=>$vo) {
foreach ($vo['img'] as $k=>$v){
$fileData = file_get_contents(dirname($_SERVER['SCRIPT_FILENAME']).$v);
$temp = explode('.', $v);
$ext = $temp[count($temp)-1];
$rand = mt_rand(0000,9999);
if ($fileData) {
$zip->addFromString($vo['k']. '_' . $rand . '.' . $ext, $fileData);
}
}
}
$zip->close();
$file = fopen($filename, "r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($filename));
Header("Content-Disposition: attachment; filename=$name.zip");
$buffer = 1024;
while (!feof($file)) {
$file_data = fread($file, $buffer);
echo $file_data;
}
fclose($file);
unlink($filename);
}
|