2015-10-13 61 views
3

你能幫我解決一個愚蠢的問題:( 我已經在laravel流明下上傳圖片在project-root/storage/products 但我不知道如何檢查瀏覽器中上傳的圖像,我的存儲文件夾在公共目錄之外,我已經試圖如何在laravel流明的web瀏覽器中查看上傳的圖像?

http://192.168.11.102:8000/storage/products/upc_1443002080.jpg 
http://192.168.11.102:8000/index.php/storage/products/upc_1443002080.jpg 

,但我得到了 - 對不起,您要找的頁面無法found.Can請你幫我

更新 這樣當你說,我已經創建路線? -

$app->get('products/{filename}', function ($filename) { 
$path = storage_path().'/products/'.$filename; 

if (file_exists($path)) { 
    return Response::download($path); 
}}); 

但是當我點擊http://192.168.11.102:8000/storage/products/upc_1443002080.jpg 它正在下載文件而不是顯示在瀏覽器中。你有什麼主意嗎? 我在響應::下載功能如下代碼 -

public static function download($file, $name = null, array $headers = [], $disposition = 'attachment') 
{ 
    $response = new BinaryFileResponse($file, 200, $headers, true, $disposition); 
    if (! is_null($name)) { 
     return $response->setContentDisposition($disposition, $name, str_replace('%', '', Str::ascii($name))); 
    } 
    return $response; 
} 

回答

1

存儲在存儲目錄中的文件受到保護。文檔根目錄是/ public。要在瀏覽器中查看上傳的項目,您需要創建一個接受文件名的路由,然後控制器將獲取該文件。

相關問題