这些是我在控制器中尝试获取图像作为响应的不同方式。
我的图像驻留在public folder/img
.
switch ($document->ext) {
case 'doc':
$img = File::get(url('/img/doc.png'));
break;
case 'docx':
$img = File::get(asset('/img/docx.jpg'));
break;
case 'pdf':
$img = File::get(public_path('/img/pdf.png'));
break;
case 'ppt':
$img = File::get(url(public_path('/img/ppt.png')));
break;
default:
}
return new Response($img, 200);
Run Code Online (Sandbox Code Playgroud)