0
votes

I'm trying to get the user image in our application when downloading pdf, my problem now is that the uploaded images will display Image not found or type unknown. Tried what was suggested here, but got no luck. My image url is in full path like http://localhost/storage/app/public/pic/user_pic/82ac9404bdb74d0ad980a30faadeab22cd41b38d.jpg. I also tried doing it this way : <td><img src="{{ public_path("storage/pic/user_pic/". basename($data->pic_path)) }}" style="height:200px; width:300px"><td>, and still no luck. Here's my full code in downloading the pdf:

Controller

$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'));

view

<tr>
    <td><img src="{{$users->pic_path}}" style="height:200px; width:300px"></td>
</tr>

Someone has an idea on this?

1
Someone has any idea on this please? Thank you. - Eem Jee
What's in $users->pic_path ? Path or url? I think Dompdf requires the url to work. - Sir_Faenor
@Sir_Faenor It's a server path since it is uploaded in our system. localhost/storage/app/public/pic/user_pic/… - Eem Jee
Can you convert it to a relative url? See this: stackoverflow.com/a/51262085/1095913 - Sir_Faenor
@Sir_Faenor Tried it, but I have error: fopen(http://localhost/storage/app/public/pic/user_pic/82ac9404bdb74d0ad980a30faadeab22cd41b38d.jpg): failed to open stream: Cannot assign requested address - Eem Jee

1 Answers

0
votes

As you use File Storage system in Laravel, you use

php artisan storage:link

to access to a readable/writable path. In my case:

storage -> /var/www/mysite.com/storage/app/public

So I use

<img src="{{ public_path().'/storage/logo-1.png' }}">

This implies that my logo is located in

/var/www/mysite.com/storage/app/public/logo-1.png

In your case:

<img src="{{ public_path().'/storage/pic/user_pic/82ac9404bdb74d0ad980a30faadeab22cd41b38d.jpg' }}">

I hope this help you!