2017-05-05 52 views
1

我已經存儲在數據庫中的圖像作爲公約/ convention_title.jpg404未找到網頁當觀看圖像Laravel

該文件位於「存儲/應用/公約/ convention_title.jpg」

當我做這樣的事情傳單}}「>,它不顯示...

OR

傳單}}「>圖像仍然不會顯示...

而且更要命的是,如果我嘗試直接通過這樣的鏈接訪問圖像...

http://localhost:8000/storage/app/convention/convention_title.jpg我得到一個查看未找到錯誤 - >未找到404頁面。

這可能是什麼原因?

回答

0

Web內容必須存儲在laravel根目錄/public文件夾中,並且您可以通過asset helper輕鬆訪問它。

例如:

/public/img/conventions/convention_title.jpg

然後你就可以在視圖來訪問它想:

{{ asset("/img/conventions/convention_title.jpg")}}

如果你想測試你是否能訪問到的圖像,你可以試試:

http://localhost:8000/convention/convention_title.jpg 
+0

感謝好友...如何將圖片上傳到公用文件夾? –

+0

你可以看看@InspiredPrynceKaka https://laracasts.com/discuss/channels/laravel/image-upload-using-storage-function-to-public-folder?page=1 – Troyer

0

你可以創建一個新的磁盤配置/ filesystems.php

'disks' => [ 
    'local' => [ 
     'driver' => 'local', 
     'root' => storage_path(), 
    ], 
    'uploads' => [ 
     'driver' => 'local', 
     'root' => public_path() . '/uploads', 
    ], 
] 

然後使用它:

Storage::disk('uploads')->put('filename', $file_content); 

或者你也可以做到這一點簡單的方法

$request->file('photo')->move(public_path("/uploads"), $newfilename); 

然後,使用上述任何一種方法,仍然可以使用資產()輔助功能訪問您的圖像...