Forum


Replies: 3   Views: 4522
Downloaded word document says it's corrupted
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 admin@wotbot.com.au  · 03-11-2017 - 08:34

Hello, I use laravel and I used the namespace version of phpdocx. I followed the instructions with the header, but the generated document says it's corrupted. Here's the code.

public function downloadWordDocument($documentId)
{
    $result = $this->initializeDocument($documentId);
    if ($result) {
        $this->_wordClient->render();
        $document    = $result['document'];
        $shaFileName = $result['sha'] . '.docx';
        $filePath    = Storage::disk('temp')->getDriver()->getAdapter()->getPathPrefix() . $shaFileName;
        $title       = $document->template->enable_prefix ? "{$document->code} {$document->title}" : $document->title;

        return response()->download($filePath, $title . ".docx", [
            'Content-Type' => 'application/vnd.openxmlformats-officedocument.' .
                'wordprocessingml.document',
            'Content-Disposition'       => 'attachment; filename="' . $title . '.docx"',
            'Content-Transfer-Encoding' => 'binary',
            'Content-Length'            => filesize($filePath)
        ]);
    }
}