【问题标题】:Laravel 5.5 image is not showing from storage/appLaravel 5.5 图像未从存储/应用程序中显示
【发布时间】:2018-10-20 11:15:34
【问题描述】:

我正在使用 laravel 5.5。我有一个表格来上传图片。这些图像存储在storage/app 文件夹中。它工作正常。但是当我尝试展示这些图像时。那些没有显示。 我已经尝试过使用这些方法来打印我的图像。

<img src="{{ asset('storage/1539872957.a-nice-place-to-picnic.jpg')}}" alt=""> <img class="user_avatar" src="{{ url('storage/app/1539872897.IMG_20180804_120323.jpg') }}"> <img class="user_avatar" src="<?php echo asset('storage/1539455504.prakruth-resort.jpg');?>">

在这里,我将图像名称作为静态名称仅用于检查。

我也完成了php artisan storage:link,并在公用文件夹中创建了一个名为“storage”的快捷方式文件夹。但是没有显示静止图像。

【问题讨论】:

  • 它们必须在 storage/app/public 中
  • 图片在浏览器中加载时形成的源url是什么?
  • @IvanJelev 即使它不允许我将文件上传到存储/应用文件夹之外。我修改了 filesystem.php 文件夹。但是那些仍然存储到 storage/app 文件夹中。所以我想从这个文件夹中显示它们。
  • @KamalPaliwal 这是输出&lt;img src="http://localhost:8000/storage/1539872957.a-nice-place-to-picnic.jpg" alt=""&gt;&lt;img class="user_avatar" src="http://localhost:8000/storage/app/1539872897.IMG_20180804_120323.jpg"&gt;&lt;img class="user_avatar" src="http://localhost:8000/storage/1539455504.prakruth-resort.jpg"&gt;
  • 当您访问 /storage/image.jpg 时,您的图像必须在 laravelFolder/storage/app/public 文件夹中,而不是在 storage/app 中。示例:/www/laravel/storage/app/public/image1.jpg

标签: laravel


【解决方案1】:

我认为this 回答会帮助你。

您必须首先通过此命令创建从 public/storage 到 storage/app/public 的符号链接

`php artisan storage:link`

现在/storage/app/public 中的任何文件都可以通过如下链接访问:

http://somedomain.com/storage/image.jpg

在你的控制器中使用这样的公共驱动程序:

 \Storage::disk('public')->put('file.png',file_get_contents($request->file->getRealPath()));

上面的 file.png 将存储在“public/storage”中。

现在您可以像这样访问图像文件:

&lt;img src="{{ asset('storage/file.png'); }}" /&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 2020-12-10
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 2018-12-26
    • 2018-01-15
    相关资源
    最近更新 更多