public function productDownload()
{
$id = intval(input('id', 0));
$product = $this->opDataModel->setTable('photo_product')->where('id', $id)->find();
if(empty($product)){
return $this->output(0, '作品不存在');
}
$photoOrigin = $this->opDataModel->setTable('photo_image')->where('product_id', $id)->column('photo_origin');
if(empty($photoOrigin)){
return $this->output(0, '作品不存在图片');
}
$tmpFile = tempnam(sys_get_temp_dir(), 'photo_');
if(!$tmpFile){
return $this->output(0, 'system error');
}
$zip = new \ZipArchive();
$zip->open($tmpFile, \ZipArchive::CREATE);
foreach($photoOrigin as $v){
$fileContent = file_get_contents($v);
$zip->addFromString(basename($v), $fileContent);
}
$zip->close();
$out = "{$product['activity_id']}-{$product['id']}-".mb_substr($product['name'], 0, 10).'.zip';
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$out);
header('Content-Length: ' . filesize($tmpFile));
readfile($tmpFile);
unlink($tmpFile);
exit;
}
使用PHP打包下载图片,zip压缩
最新推荐文章于 2023-09-14 11:11:53 发布