【发布时间】:2020-03-07 20:18:39
【问题描述】:
我在下载pdf时试图在我们的应用程序中获取用户图像,我现在的问题是上传的图像将显示Image not found or type unknown。尝试了here 的建议,但没有运气。我的图片网址位于完整路径中,例如 http://localhost/storage/app/public/pic/user_pic/82ac9404bdb74d0ad980a30faadeab22cd41b38d.jpg。我也尝试过这样做:
<td><img src="{{ public_path("storage/pic/user_pic/". basename($data->pic_path)) }}" style="height:200px; width:300px"><td>,仍然没有运气。这是我下载pdf的完整代码:
控制器
$users = $this->userListService->getUserDataPDF($request);
$pdf = PDF::loadView('pdf.user_pdf', compact('guests'))->setPaper('','landscape');
$pdf->getDomPDF()->setHttpContext(
stream_context_create([
'ssl' => [
'allow_self_signed'=> TRUE,
'verify_peer' => FALSE,
'verify_peer_name' => FALSE,
]
])
);
return $pdf->download(Carbon::now()->format('Ymd') . 'user.pdf',compact('users','pdf'));
查看
<tr>
<td><img src="{{$users->pic_path}}" style="height:200px; width:300px"></td>
</tr>
有人对此有想法吗?
【问题讨论】:
-
有人对此有任何想法吗?谢谢。
-
$users->pic_path中有什么内容?路径还是网址?我认为 Dompdf 需要 url 才能工作。 -
@Sir_Faenor 这是一个服务器路径,因为它是在我们的系统中上传的。 localhost/storage/app/public/pic/user_pic/…
-
你能把它转换成相对网址吗?看到这个:stackoverflow.com/a/51262085/1095913
-
@Sir_Faenor 试过了,但我有错误:
fopen(http://localhost/storage/app/public/pic/user_pic/82ac9404bdb74d0ad980a30faadeab22cd41b38d.jpg): failed to open stream: Cannot assign requested address