如何在Laravel中获取文件的内容

时间:2017-04-19 16:16:37

标签: php laravel pdf

我试图用PDF和微软的单词阅读我上传的文档的内容,但是返回的内容只是一些不可读的字符,任何人都可以帮我解决错误

这是我的代码

$file = ReportAttachment::find($id);
if (File::isFile(public_path('report_attachments/'.$file->report_path))){
$path = public_path('report_attachments/'.$file->report_path);
$content = File::get($path);
dd($content);
return (new \Illuminate\Http\Response($file, 200))
->header('Content-Type',$file->mime);
}

提前致谢

1 个答案:

答案 0 :(得分:0)

经过一些调试后,我使用public_path从公共文件夹更改了存储,使用本地存储来存储文件,这里是已编辑的代码

if (File::isFile(storage_path('app/'.$file->report_path))){
$path = storage_path('app/'.$file->report_path);
$content = File::get($path);
$file = Storage::disk('local')->get($file->report_path);;
$response = Response::make($file, 200);
$response->header('Content-Type', $file->mime');
return $response;
}