2017-08-14 42 views
1

在我的本地機器項目工作文件上,但是當我上傳到我的服務器上時,所有圖像都不顯示,而當我點擊瀏覽器的完整圖像路徑時,NotFoundHttpException錯誤。Laravel圖像沒有在服務器上顯示,並在我的本地機器上正常工作

mypath中項目是

/public_html/offlinemall/public 

而下面是我filesystems.php

'disks' => [ 

    'local' => [ 
     'driver' => 'local', 
     'root' => storage_path('app'), 
    ], 

    'public' => [ 
     'driver' => 'local', 
     'root' => storage_path('app/public'), 
     'url' => env('APP_URL').'/storage', 
     'visibility' => 'public', 
    ], 

    's3' => [ 
     'driver' => 's3', 
     'key' => env('AWS_KEY'), 
     'secret' => env('AWS_SECRET'), 
     'region' => env('AWS_REGION'), 
     'bucket' => env('AWS_BUCKET'), 
    ], 
    'featured' => [ 
     'driver' => 'local', 
     'root' => storage_path('app/public'), 
     'url' => env('APP_URL').'/storage', 
     'visibility' => 'public', 
    ], 

], 

,我怎麼得到的圖像

<img style="height: 480px" src="storage/{{ $ad->avatar }}"> 

在檢查我得到完整的路徑,但是當我打了網址,然後我得到NotFoundHttpException錯誤。

http://compare.theofflinemall.com/storage/featured_image/qzHWpQeSfKjZ6DOS59ROyYboJ1GCvVi6NNVfLtVV.jpeg 
+0

你有在'公共/ storage'文件夾?如果它不在'/ public'中,則它不可公開訪問,並且必須通過控制器訪問。 – aynber

+0

@aynber我創建了一個從公共/存儲到存儲/應用程序/公共的符號鏈接由PHP artisan存儲:鏈接命令 –

+0

檢查您的公共文件夾有存儲鏈接或不生成的PHP artisan存儲:鏈接命令? –

回答

0

您的服務器無法找到storage的路徑,因爲它使用public_path 運行

php artisan storage:link 

它應該工作。另外,儘量使用

{{ asset('storage/'.$ad->avatar) }} 
+0

無法正常工作。我在本地嘗試並在那裏工作,但在我的服務器上出現同樣的錯誤。 –

0

您可以更改圖像標籤:

  1. <img src={{ asset('storage/'.$ad->avatar) }} />
  2. <img src="storage/app/public/{{$ad->avatar) }}" />
  3. <img src="<?php echo asset("storage/app/public/$ad->avatar")?>"></img>
+0

@M Idrees我給項目路徑/ public_html/offlinemall/public,所以我不能從公開回去。 –

+0

沒有必要從'public'回去。 –

相關問題