[英]Laravel - resolving uploaded image path
我上傳的圖片位於storage/app/spreferenceimages
圖像路徑以以下方式存儲在數據庫中: spreferenceimages/laravel-generated-filename.ext
我正在嘗試使用我認為的路徑。 我嘗試了asset()
助手:
<img src="{{ asset($spreference->favicon) }}">
但它返回NotFoundException
。 生成的網址是:
http://localhost:3000/spreferenceimages/v2hM7nJcSWdXCAh7RdJUR4CExAMQfk1XX0u4ZiX1.png
如何直接使用存儲文件夾(而不必在公用文件夾中生成符號鏈接)?
您應該創建一個符號鏈接 :
php artisan storage:link
這將創建一個從public/storage
到storage/app/public
的符號鏈接,因為最終用戶只能訪問storage/app/public
。
然后,您可以訪問圖像:
http://localhost:3000/storage/v2hM7nJcSWdXCAh7RdJUR4CExAMQfk1XX0u4ZiX1.png
您可以創建訪問文件的路徑或將文件直接上傳到公用文件夾
使用路線的示例:
Route::get('image/{path}', function(){
return Storage::get($path);
})->name('image');
//acess the image
<img src="{{ route('image', $spreference->favicon) }}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.