Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Oscar Merida:
Creating ZIP files and streaming the response with Silex
Jan 19, 2018 @ 17:28:44

On his site Oscar Merida has shared a post showing how to create a ZIP file and stream the response in a Silex-based application using the DOMPDF library and PHP's ZipArchive functionality.

Creating a zip file is easy and Rob Allen has you covered on that front to get you started. I needed to do this to create a zip file of PDF files generated by Dompdf. It turns out, you can add files to a ZipArchive object without actually creating the file if you can get the contents as a string.

The post includes the code to create the DOMPDF instance, load the HTML and render the result. From there the ZipArchive takes over and creates the archive from the PDF result. Finally the code takes the ZIP archive as input and pushes it out with a custom header to tell the browser to download it and streams back the raw ZIP contents.

tagged: tutorial silex dompdf pdf zip archive silex stream download

Link: http://oscarm.org/2018/01/stream-a-zip-file-via-silex/


Trending Topics: