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?.