Forum


Replies: 10   Views: 4046
Createdocx gives a corrupted document
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 tutotours  · 15-09-2017 - 14:19

Hello !

 

I generate docx documents with CreateDocx method. When I download them, I always get a corrupted file. Word is asking me if I want to recover it. When I do, I get back all the content there should be. But at first, the file is still corrupted.

I get this error with trial package but also with premium package.

Why is that ?

Posted by admin  · 15-09-2017 - 14:46

Hello,

That's a generic error from MS Word that appears when your server is not returning the right DOCX mime type or there's some wrong or missing content. It's the equivalent to an error 500 of PHP.

We recommended you to download the DOCX without using the web server to check it the problem comes from a wrong mime type; for example using FTP or SFTP and then open it with MS Word. If the issue keep going, please split your code to find the source of the error (first run a few lines and check if it opens fine, then the next ones and so on).

Regards.

Posted by tutotours  · 15-09-2017 - 16:02

Actually, documents I generate with CreateDocx are not saved but directly streamed.

I tried to set stream to false in configuration but it still downloads files.

Posted by admin  · 15-09-2017 - 16:07

Hello,

Please run one of the included samples in the package.

The library doesn't download the DOCX unless you enable the stream mode or use the createDocxAndDownload method. Using the createDocx method without the stream mode, it generates the DOCX but it's not downloaded.

Regards.

Posted by tutotours  · 15-09-2017 - 16:30

I tried with this code : 

 

$docx = new CreateDocx();
$docx->createDocx();

And also this code :

$docx = new CreateDocxFromTemplate('document.docx');
$docx->createDocx('document.docx');

Without anything else and it still giving me something corrupted.

 

If it's because of the web server, how can I get this right ?

Posted by admin  · 15-09-2017 - 16:32

Hello,

You need to add at least one content. Please run one of the included samples, such as examples/Core/addText/sample_1.php, this it's the simplest example included with the library.

Regards.

Posted by tutotours  · 15-09-2017 - 16:35

It's the same with the samples.

Posted by admin  · 15-09-2017 - 16:40

Hello,

Please send the DOCX generated by examples/Core/addText/sample_1.php to contact[at]phpdocx.com

There must be some wrong configuration on your server if the DOCX are generated corrupted.

Regards.

Posted by tutotours  · 15-09-2017 - 16:48

I've just sent you the file.

Posted by admin  · 15-09-2017 - 17:15

Hello,

We have checked your DOCX. The problem is that Symfony is returning errors from your code:
 

<!DOCTYPE h
00006a68:  746d 6c3e 0a3c 6874 6d6c 3e0a 2020 2020 3c68 6561 643e 0a20  :tml>.<html>.    <head>.
00006a80:Â  2020 2020 2020 203c 6d65 7461 2063 6861 7273 6574 3d22 5554Â  :Â Â Â Â Â Â  <meta charset="UT
00006a98:  462d 3822 202f 3e0a 2020 2020 2020 2020 3c6d 6574 6120 6e61  :F-8" />.        <meta na
00006ab0:Â  6d65 3d22 726f 626f 7473 2220 636f 6e74 656e 743d 226e 6f69Â  :me="robots" content="noi
00006ac8:  6e64 6578 2c6e 6f66 6f6c 6c6f 7722 202f 3e0a 2020 2020 2020  :ndex,nofollow" />.     
00006ae0:Â  2020 3c6d 6574 6120 6e61 6d65 3d22 7669 6577 706f 7274 2220Â  :Â  <meta name="viewport"
00006af8:Â  636f 6e74 656e 743d 2277 6964 7468 3d64 6576 6963 652d 7769Â  :content="width=device-wi
00006b10:  6474 682c 696e 6974 6961 6c2d 7363 616c 653d 3122 202f 3e0a  :dth,initial-scale=1" />.
00006b28:Â  2020 2020 2020 2020 3c74 6974 6c65 3e20 2020 2054 6865 2063Â  :Â Â Â Â Â Â Â  <title>Â Â Â  The c
00006b40:Â  6f6e 7472 6f6c 6c65 7220 6d75 7374 2072 6574 7572 6e20 6120Â  :ontroller must return a
00006b58:Â  7265 7370 6f6e 7365 2028 6e75 6c6c 2067 6976 656e 292e 2044Â  :response (null given). D
00006b70:Â  6964 2079 6f75 2066 6f72 6765 7420 746f 2061 6464 2061 2072Â  :id you forget to add a r
00006b88:Â  6574 7572 6e20 7374 6174 656d 656e 7420 736f 6d65 7768 6572Â  :eturn statement somewher
00006ba0:Â  6520 696e 2079 6f75 7220 636f 6e74 726f 6c6c 6572 3f20 2835Â  :e in your controller? (5
00006bb8:Â  3030 2049 6e74 6572 6e61 6c20 5365 7276 6572 2045 7272 6f72Â  :00 Internal Server Error
00006bd0:  290a 3c2f 7469 746c 653e 0a20 2020 2020 2020 203c 6c69 6e6b  :).</title>.        <link


If you open the DOCX with a HEX viewer you can see the whole content of the errors.

If you run phpdocx standalone you can check everything is generated fine and DOCX is not corrupted. We recommend you to check your server and Symfony logs the find the source of that error messages (seems something wrong with a Controller).

Regards.

Posted by tutotours  · 15-09-2017 - 20:15

I didn't see it but I had an error in Symfony as you said. I forgot to add a return Response. 

 

Problem solved. Thank you very much for your time.