[英]Laravel - Can't find an image, though it is there in the disk. Can't reach it even through typing the URL
所以我正在 Laravel 中構建一個應用程序,這是我第一次在沒有互聯網幫助的情況下獨自使用該框架,所以我在某些方面遇到了很多麻煩。 其中之一是,即使我上傳的圖像被上傳到文件系統中的正確位置,laravel 似乎也無法找到並提供它們。 我正在與 Valet 一起處理我的本地環境。 此外,我已經按照文檔的指示在存儲和公共之間建立了符號鏈接。
這是上傳圖片的代碼:
$fileDir = 'public/enterprise/main';
$tempImage = request()->file('main_img');
$newImage = $tempImage->store($fileDir);
這就是我試圖稱呼它的方式:
<div class="col-xs-8"><img src="{{ asset('storage/app/'.$enterprise->main_img) }}"></div>
laravel 似乎試圖達到的網址是這樣的:
http://vbi.dev/storage/app/public/enterprise/main/MgfjPKWL8DIFgHDrMccOCsOkZZH0QmFAsput07n5.jpeg
最后,我的配置/文件系統文件:
<?php
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
'img' => [
'driver' => 'local',
'root' => storage_path('images')
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
];
感謝您的關注。
您應該只傳遞在 public 目錄中存儲文件的文件夾,而不包括public
,並且您可以在第二個參數中指定一個磁盤,如下所示:
$fileDir = 'enterprise/main';
$tempImage = request()->file('main_img');
$newImage = $tempImage->store($fileDir, 'public');
同樣在視圖中,資產方法會自動為您添加公用文件夾的路徑:
<div class="col-xs-8"><img src="{{ asset($enterprise->main_img) }}"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.