強制ダウンロードでは、まずファイルヘッダーを送信する必要があります。
header('content-type: application/zip');
header('content-disposition: inline; filename=YOUR_ZIP_FILE_NAME_HERE.ZIP"');
ジッピングでは、1つのPHPのzipライブラリを使用して、圧縮されたコンテンツをエコー/出力します。
http://ca3.php.net/manual/en/zip.examples.php
このような何か:
$zip = new ZipArchive();
//the string "file1" is the name we're assigning the file in the archive
$zip->addFile(file_get_contents($filepath1), 'file1'); //file 1 that you want compressed
$zip->addFile(file_get_contents($filepath2), 'file2'); //file 2 that you want compressed
$zip->addFile(file_get_contents($filepath3), 'file3'); //file 3 that you want compressed
echo $zip->file(); //this sends the compressed archive to the output buffer instead of writing it to a file.
出典
2009-06-05 02:21:59
Ian
実際に実際にzipファイルを作成し、保存せずに「オンザフライ」ZIPファイルを作成する方法はありますか? またはこれはこれを実行しますか? –
この例では、ファイルを保存せず、エコーする前にメモリに保存しています。 "file1"、 "file2"、および "file3"は、圧縮を要求したファイルです。 – Ian