因此,對於那些誰感興趣的話,我用下面的代碼從SO提到上面張貼:
// Prepare File
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
// Stuff with content
$zip->addFromString('file_name_within_archive.ext', $your_string_data);
$zip->addFile('file_on_server.ext', 'second_file_name_within_archive.ext');
// Close and send to users
$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="file.zip"');
readfile($file);
unlink($file);
相應調整了我的要求和它的作品。
看一看https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly – Richard
你的一個紳士,我設法從這個工作,並得到它的工作,我想如何: ) – CrispyDuck
對於你的信息,你可以使用密碼保護它:'$ zip-> setPassword(「YourPasswordHere」);' – Richard