Replies: 1   Views: 1142
Multiple docx documents in a zip file
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by pwctechnicalsecurity  · 25-03-2021 - 14:50


We have a Premium license of PhpDocX. I am curious whether it is possible to create multiple DocX documents in a stream setting and have all of these documents combined in one Zip archive. I have noticed the ZipStream concept, but that does not seem to be fully applicable. Is there some working example available or could you provide such a quick snippet?

Ambition is to have multiple documents in a Zip without them touching the filesystem.

Kind regards!


Posted by admin  · 25-03-2021 - 17:11


phpdocx Premium licenses can generate a DOCX as a stream using the included ZipStream class, but this class doesn't allow adding streams to generate a new ZIP file that includes them (ZipStream uses gzcompress that doesn't allow adding streams/objects). phpdocx doesn't include a class to generate a ZIP stream that include DOCX streams.

PHP ZipArchive doesn't support adding streams (only files and strings), so an external library or tool should be used.  Maybe ZipStream-PHP ( is a good solution, you can generate DOCX streams using phpdocx and using that library you could generate a new ZIP from these strings. Or you can use a RAM disk ( to avoid generating the DOCX in the filesystem.