$file_name = 'cqi-' . $date->format('Ymd') . '-' . 'id' . strval($iid) . $extension;
$data_path = Storage::path("attachments/product/{$aid}/{$item_name}");
private static function imgZipDownload($file_infos){
$date = Carbon::now();
//■zipファイル
// 出来上がるzipのファイル名
$zip_file_name = "cqi-{$date->format('Ymd')}-{$date->format('His')}.zip";
$tmp = "tmpzip";
if (!file_exists($tmp)) {
if (!mkdir($tmp, 0777, true)) {
abort(400,"{$tmp}の作成に失敗しました");
}
}
$zip = new ZipArchive();
$zip->open("tmpzip/{$zip_file_name}", ZipArchive::CREATE);
foreach($file_infos as $f){
// zipにしたいファイルを追加
// $zip->addFile('img/sumi.png', 'sumi.png');
$zip->addFile($f->path,$f->name);
}
// zipファイル作成
$zip->close();
//■自動ダウンロード
header('Content-Type: application/zip; name="' . $zip_file_name . '"');
header('Content-Disposition: attachment; filename="' . $zip_file_name . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize("tmpzip/{$zip_file_name}"));
// header('Content-Length: ' . filesize($zipDir . $zipFileName));
header('Connection: close');
while (ob_get_level()) {
ob_end_clean();
}
readfile("tmpzip/{$zip_file_name}");
unlink("tmpzip/{$zip_file_name}");
exit;
}
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme