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) ]); } }