Forum


Replies: 8   Views: 4468
Corrupt file when calling createdocxanddownload
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 liam.whan  · 10-10-2012 - 06:14

Hi All,

When I call createDocx the file output is fine but when I call createDocxAndDownload Word 2010 Windows 7 Home Premium x64 displays an error message saying that the file is corrupted.

Any ideas?

Cheers,


Liam

Posted by admin  · 11-04-2013 - 12:13

Hello,

Please check your MIME types. DOCX must have this one:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

Regards.

Posted by liam.whan  · 11-04-2013 - 12:13

Hi there, thanks for replying my MIME Types are set to:

AddType application/vnd.ms-word.document.macroEnabled.12 .docm
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
AddType application/vnd.ms-powerpoint.template.macroEnabled.12 potm
AddType application/vnd.openxmlformats-officedocument.presentationml.template potx
AddType application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
AddType application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
AddType application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
AddType application/vnd.ms-excel.addin.macroEnabled.12 xlam
AddType application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
AddType application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
AddType application/vnd.ms-excel.template.macroEnabled.12 xltm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx

Are lines 2 and 3 correct?

Posted by liam.whan  · 11-04-2013 - 12:13

My MIME types look appropriately set up.

Please advise.

Posted by admin  · 11-04-2013 - 12:13

Hello,

Check lines 4638-4646 in CreateDocx.inc class. There're three headers that you can customize; If you post your web server and version (Apache, IIS, ...) we'll test it.

createDocxAndDownload method uses createDocx to create the DOCX, so the file is the same but there must be something missing related to headers.

Regards.

Posted by liam.whan  · 11-04-2013 - 12:13

hi there.

I'm on a XAMPP dev server at the moment. Apache 2.2, PHP 5.4.4


Its definately a header issue (im still new to headers so I'm not 100% ok with them) but I found a workaround:

if I edit CreateDocx.inc and call ob_clean() and flush() (passing no arguments) directly after header('Content-Transfer-Encoding: binary); I get the desired output.

Posted by admin  · 11-04-2013 - 12:13

Hello,

We'll check that server config to solve any issues.

Regards.

Posted by cgsmith  · 11-04-2013 - 12:13

[quote][b]Quote from liam.whan on October 12, 2012, 00:08[/b]

if I edit CreateDocx.inc and call ob_clean() and flush() (passing no arguments) directly after header('Content-Transfer-Encoding: binary); I get the desired output.

[/quote]

Thanks for this tip. This has helped me as well.