Forum


Replies: 2   Views: 3565
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');

Which results in:

PK   ½–¸Ä               [Content_Types].xmlÅWKoÛ0¾÷Wº±Ò†!Nëvì
¬vU$ÚÑj= 1móï'ÙŽ±uNäÕõv1`ŠßC¤`Ñ«ëgUgÂà ¼4º ù’d ¹RWùvÿyñžd™¬6
²O®×g«û½Ÿ°öÙ"Úâ€z¾Å|n,è°R§†WWQËø«€^.—ï(7Aã#Y¯n d»³OÃ!ÃœqP{’}l£VA˜µµäÃ:}Ôâ…Ê¢SȲÉñ[iýyH tP!®èp_BeÅ“ÂÃ1‡·L…,údœ ÂðÂ
Èü4ÀOS–’CÂÂlÖÞ‡’«:ïW“úü„¾óhÔwUS‰ îœ±þb²Âž4òÂC  þ/=\þkM?ôNmÀ…
¾}Czê¤ ÂûüÛ;hyÓò€ s蘓ž`óu6¿Â'Ââ€Ã†Â 68G7zê¤     Ãb&椅-0núwá-ñHýéß„×êÇfòÿ–x¤þû©ß–éê?×ýÑõzlSÃ:ê¤        c´Ãé'±¡9%2›‹8Å’YîÛ>ÃŒQ½°£nà ^1POÞÄM€Ã˜â*Y¾P“*ÃŽâ„¢1¾ÎV´ƒbØjã)¬ÕÃØOëÂ1aH£7Ê‚cü7ìÑãÈŠ•žáZ:0F›¿„õÙOPKºÃÛ:ù  f  PK   ½–¸Ä               _rels/.rels­’ÃjÃ0@ïƒýƒÑ½QÚãN/cÃÛÙ[ILÛØj×þý<ØØ]éaGËÒÓ“ÃzsÅ“Fuà â€]ð–U
Š½    Öù^Ã[û¼x •…¼¥1xÖpâ›æöfýÊ#I)ʃ‹YŠÑøˆ˜ÃÀå*Döå§i")ÃÔc$³£žqU×÷˜~3 ™1ÕÖjH[{ª=E¾†ºÎ~
f?±—3-ÂÂÂÞ²]ÄTꓸ2Âj)õ,l0/%œ‘b¬
ð¼Ñêz£¿§Å‰…,       ¡  ‰/û|f\ZþçŠæ?6ï!Y´_áoÅ“]AóPK‘·é   N  PK   ½–¸Ä               word/_rels/document.xml.rels½VMSÂ0½û+:¹Ûâ€â€šâ‚¬Ãª/Å 3^C»@¥Ùt’åëßEhQÃŒp÷e²ïå½MÚþp#‹`Úä
Ö# ¦*Ëq–°×ñãu—†f¢P       Û‚aÃÃUÿ
AvÂ™ç¥    l4      ›•=ÃŽM:)L¨J@»2UZ
²¥žñR¤1GQݑz68ꌲ„éQféÇÛÎé­¦Ó<…{•.% Â à €*²'ÆBÃۦGBÛ‹ñÓMŸ¦ÊòéJîŽ]¼òãRN@Ûx+      È%¢ãÛ„I gñå£h8xµÂì^¨ø¿ÊèáÕ„tiHÉ7ËvÆÊséœÎFÛo&Hc1) Ë7äTñßž8òjÉ&/@dïgíºÔ@§-^}™ƒÈêfW;§ãÆ'¿ùeÆ’9ǯN?M§€èò!8DZå5Úõ‡{Wȏo½ßvÃ’EŽ‹JÂyAª·ÎßQ Ã-Wâáê>©Ì2?llH(þŽÈ«E§#rÃŽH+Ž:è{ýÖ§J~.ÕÂÚ#{)üè?npõPKoÀ\ò   
  PK   ½–¸Ä               word/endnotes.xml½–ÛŽ›0†ï÷)ÂïIØ…¬Ô&­ö®j¶à 5N°d›Þ¾¤K"õ†“ýþg<±z9±Ô9¥©à ð¦.pÇ"¦üÂßoß'Kà hÆ’xÅ’RÃI
¢ÃËúi•‡„Ç\¢Kà :ÃŒ%Ž@bÅ’!Ô8!é)£X      -öfÅ Æ’b¿§˜À\¨ú®çVOR       L´¶Ë}Cüˆ48ãði-V(·â8‡8AÊÂSÇðî†,à ¸ìƒü ¡ïõQ³»Q,]õ@óQ ëªGZÅ’#]    .Gòû¤çq¤YŸ´Gê•ë¸Â„ÛýPûªÂ!õ‘ɉKdè;M©),Ó
¢üc„#«j       lßMx†LÄ$ÂÃ…
ED S<<ë'­¾´Öúó­Q¨!ñ×’ÂÀ#ÃœT‘CER›ÃuBe{ÂÙXÅ¡LÈñVG–‚¶;yÂË¿ÚÓ¦Nebÿœ–ÖÎo=wÀŽâ€Ë†V1ÄÂßk6N˜­ÂnáQ©¹H®7°Â4 ¿0XÃ’
#83 U^p4¹³h0º`ÃQÃåá±jù¡D&;}ŒöÚÂýœß |

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!