英文:
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([
'SittingRoom'=> request()->file('sittingroom')->store('apartments')
]);
bladeview.php
<img src="{{asset('storage/'.$duplex->SittingRoom)}}">
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
'default' => env('FILESYSTEM_DISK', 'public'),
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论