php - 无法在 Laravel 中检索上传的图像文件的 URL
问题描述
我上传的文件 (abc.png) 保存在文件夹中:
storage\app\public\uploaded_files\abc.png
当我使用$url = Storage::disk('public')->url($business->logo);
它时,它会生成http://127.0.0.1:8000//storage/abc.png
一个打开与路由相关的 URL。
在filesystem.php我有以下条目。
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
路线
Route::get( '/{business_slug}/{item_name}-{encoded_id}',
'ItemController@single' )->name( 'single_item' );
我应该怎么做才能修复图像 URL 并使其公开可用?
解决方案
I see that your problem has been solved, but I'll leave another solution:
If you store your file in your public folder (or a subfolder in the public folder), you can easily access the file by using
{{ asset('images/' . $image) }}
The $image is just the filename, with it`s extension, and is being linked the to the subfolder 'images' in the public folder. This will work on any sub-page.
推荐阅读
- c# - 如何直接填充 EF Core 为多对多关系生成的连接表?
- azure - 无法从 B2C / Azure AD (Active Directory) 获取令牌 - 本地存储和会话存储为空 [Cypress / Puppeteer]
- ffmpeg - 如何将 ffmpeg 输出传送到 ImageMagick 的转换工具?
- python - Python使用分隔符将对象拆分为多个字符串
- excel - 粘贴图表时的VBA Excel问题
- php - 在php中的表格单元格内实例化对象类?
- c - 您可以将任何复合类型与 C 中的 _Generic 匹配吗?
- c++ - 如何在 Microsoft Visual Studio Community 2019 中运行 Microsoft DirectShow 官方示例 C++ 代码?
- python - Python 3 嵌入式图像未附加在电子邮件中
- gtk - 从 GTK 应用程序将文件夹备份到 pemdrive