【问题标题】:Laravel Dompdf Image not found or type unknownLaravel Dompdf 图片未找到或类型未知
【发布时间】: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-&gt;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

标签: image laravel-5 dompdf


【解决方案1】:

当你在 Laravel 中使用文件存储系统时,你会使用

php artisan storage:link

访问可读/可写路径。就我而言:

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

所以我用

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

这意味着我的徽标位于

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

在你的情况下:

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

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多