Forum


Replies: 3   Views: 4756
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  · 09-11-2017 - 08:43

Gee, I apologize for the late update, I was able to fix the issue, I followed this solution https://stackoverflow.com/questions/29906595/laravel-5-file-downloads-invalid,
Again, I use laravel. But the method `ob_end_clean` is a generic PHP method, It could help others experiencing the issue even after adding the proper headers. Here's my updated code: 

public function downloadWordDocument($documentId)
{
    try {
        $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;
            ob_end_clean();
            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)
            ]);
        }
    } catch (\InvalidArgumentException $err) {
        return abort(400, $err->getMessage());
    } catch (\Exception $err) {
        return abort(400);
    }
}



Also, How do I filter through all my posts in the forum?.