Forum


Replies: 2   Views: 4249
Docx not saved to file but displayed in cli
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 rbardoel  · 24-05-2018 - 19:09

I tried to load a template from a database as described in this example:

https://www.phpdocx.com/documentation/cookbook/improve-phpdocx-performance

The script is run from command line. When I ran the code below, the docx seems to be dsplayed within the cli instead of being written to file:

$docxContent = $row['data'];
$data = base64_decode($docxContent);
$docxStructure = unserialize($data);
$docx = new Phpdocx\Create\CreateDocxFromTemplate($docxStructure);
$docx->enableCompatibilityMode();
$docx->createDocx('test');

Is this is a bug or am I overlooking something? Streaming is enabled, license is premium. Thank you in advance!

Posted by admin  · 25-05-2018 - 06:27

Hello,

If you are using the stream mode and PHP CLI, then you need to redirect the stream to an output, otherwise the content is displayed.

If you set the stream mode as true and then you open the script using a web browser, the DOCX is generated and downloaded. If you use PHP CLI you can redirect it, for example to a file:

$ php stream_mode_script.php > output.docx

or any other output. This is the way how streams work.

Regards.

Posted by rbardoel  · 25-05-2018 - 07:42

I should have known this :) Thank you for the answer, works perfect!