3

I have created multiple PDF file streams in memory. Can I create a zip file from these streams, and if so how? I want to give the user a downloaded zip of my files without creating any files on the server.

ZipArchive only appears to take file names when running addFile.

Shoreline
  • 798
  • 1
  • 9
  • 26
  • 1
    sounds like you want https://secure.php.net/manual/en/ziparchive.addfromstring.php –  Mar 09 '18 at 11:34

1 Answers1

0

I ultimately found my solution here:

Similar to the solution given there, I used the class from phpmyadmin as follows:

header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename='whatever.zip'");

$zip = new ZipFile;
foreach($pdfs as $idx => $content) {
    $zip->addFile($content, "file$idx.pdf");
}
file_put_contents("php://output", $zip->file());
Shoreline
  • 798
  • 1
  • 9
  • 26