複数のファイルをダウンロードするときはたいていzip形式に圧縮してダウンロードさせる。 その方法
zipファイルを作成
// まずpathを指定 $zipPath = 'zip/output.zip'; // zip作成 $zip = new ZipArchive; $zip->open($zipPath, ZipArchive::CREATE|ZipArchive::OVERWRITE);
zipにファイルを詰め込んでいく
左が圧縮対象のファイル、右がzipに入れる際のファイル名
zip->addFile('/hoge/fuga/photo.jpg', 'zip.jpg');
zipを閉じる
zipに全てのファイルを詰め込んだらzipを閉じる
$zip->close();
ダウンロードさせる
このあたりはダウンロード機能に関するおまじない
mb_http_output("pass"); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: Binary"); header("Content-Length: ".filesize($zipPath)); header('Content-Disposition: attachment; filename*=UTF-8\'\'output.zip'); ob_end_clean(); readfile($zipPath);