“Laravel中未在public/storage找到图像”

huangapple go评论68阅读模式
英文:

laravel image not found in public/storage

问题

我正在尝试访问我的项目中的图像。

我已经运行了php artisan storage link

Laravel创建了public/storage

当我上传图像到storage/app时,我可以在storage/app看到图像,但在public/storage中看不到。

当我尝试在浏览器上查看图像时,我收到404错误。

controller.php

Property::create([
    'SittingRoom' => request()->file('sittingroom')->store('apartments')
]);

bladeview.php

<img src="{{ asset('storage/' . $duplex->SittingRoom) }}">

浏览器链接

http://127.0.0.1:8000/storage/apartments/HNLDysVUdRG7ZTBkF2qFGk2B2tAKYzYcVImNEWLx.jpg

在运行artisan storage link后:

C:\xampp\htdocs\OPAAM> php artisan storage:link

INFO  [C:\xampp\htdocs\OPAAM\public\storage] 链接已连接到 [C:\xampp\htdocs\OPAAM\storage\app/public]。
英文:

I am trying to access images for my project.

I have run php artisan storage link

Laravel create public/storage

when I upload image to storage/app, I see the image in storage/app but not in public/storage.

When I try to view image on browser, I get error 404

controller.php

Property::create([
&#39;SittingRoom&#39;=&gt; request()-&gt;file(&#39;sittingroom&#39;)-&gt;store(&#39;apartments&#39;)
]);

bladeview.php

&lt;img src=&quot;{{asset(&#39;storage/&#39;.$duplex-&gt;SittingRoom)}}&quot;&gt;

browswer link

http://127.0.0.1:8000/storage/apartments/HNLDysVUdRG7ZTBkF2qFGk2B2tAKYzYcVImNEWLx.jpg

after running artisan storage link

C:\xampp\htdocs\OPAAM> php artisan storage:link

INFO The [C:\xampp\htdocs\OPAAM\public\storage] link has been connected to [C:\xampp\htdocs\OPAAM\storage\app/public].

答案1

得分: -2

问题出在 config/filesystems.php 文件中:

'default' => env('FILESYSTEM_DISK', 'public'),

但在 .env 文件中:

FILESYSTEM_DISK=local 

这个配置会将你的图片保存在 Storage/app 而不是 storage/app/public

storage/app 中保存的图片无法公开访问。因此,你需要修改 .env 文件。

英文:

The problem was that in config/filesystems.php

&#39;default&#39; =&gt; env(&#39;FILESYSTEM_DISK&#39;, &#39;public&#39;),

but in the .env file

FILESYSTEM_DISK=local 

This configuration saves your images in Storage/app instead of storage/app/public.

Images saved in storage/app cannot be accessed publicly.
So you have to change the .env file

huangapple
  • 本文由 发表于 2023年4月17日 22:45:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76036400.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定