Hello I'm trying to preview files from public folder so users can make sure it is the file they are trying to delete.
Here is my current code:
HTML
<a href="{{ route('preview_attachment', $material->filename) }}" class="btn btn-warning btn-sm">
Preview
</a>
Controller
public function previewAttachment($filename) {
$file = public_path('training/attachments/' . $filename);
return Response::make(file_get_contents($file), 200, array(
'Content-Type' => File::mimeType($file),
'Content-Disposition' => 'inline; filename="' . $filename . '"',
));
}
It is not working. Instead of showing a preview of the file, it prompts me to download the file. Any help please.
The filetypes range from word docs, excel, ppt, pdf, images.
Edit :
I have tried uploading images and pdf files, and it is working. however on word docs it is not working