【发布时间】:2019-12-24 04:35:45
【问题描述】:
我想在我的视图上显示图像,但我收到:File not found。
两个错误:
FileSystemAdapter.php 第 61 行中的 FileNotFoundException: storage/app/public/covers/teste-bravo_cover.jpg
FileSystem.php 第 386 行中的 FileNotFoundException:文件未找到 路径:storage/app/public/covers/teste-bravo_cover.jpg
但图片在正确的文件夹中:
好吧,在 Laravel 5.2 中 storage:link 不起作用。
磁盘上的图像存储 - 可以很好地存储图像
if($cover){
dump("ok1");
Storage::disk('public_covers')->put($covername, File::get($cover));
$coverObject = New Cover();
//path com o nome do arquivo
$coverObject->imagePath = 'storage/app/public/covers/'.$covername;
dump($coverObject->imagePath);
}
//Salva a capa com o path para o arquivo
$coverObject->save();
我的文件系统(带有“public_covers”磁盘)- 可以很好地存储图像
'public_covers' => [
'driver' => 'local',
'root' => storage_path('app/public/covers'),
'visibility' => 'public',
],
查看代码:(如果电影有封面,请显示)
@if($movie->cover)
<img src="{{route('cover.image', [$movie->cover])}}" />
@endif
路由代码,指向控制器方法
Route::get('/movieimage/{coverId}',
[
'as' => 'cover.image',
'uses' => 'MovieController@getimage'
]
);
控制器获取图像的方法
public function getimage($coverId){
$movie = Cover::find($coverId);
//dump($movie);
$imagePath = $movie['imagePath'];
dump($imagePath);
$file = Storage::disk('public_covers')->get($imagePath);
$response = Response::make($file, 200);
return $response;
}
【问题讨论】:
-
尝试使用asset helper。
-
我尝试使用
<img src="{{asset($movie->cover->imagePath)}}" />在浏览器上显示正确的路径,但不会加载图像。<img src="http://localhost:8000/storage/app/public/covers/teste-bravo_cover.jpg"> -
现在必须使用存储链接,可以回复here
-
storage:link 仅在 5.3 版本之后有效,或者不?我在运行 5.2
[Symfony\Component\Console\Exception\CommandNotFoundException] There are no commands defined in the "storage" namespace.时收到此消息
标签: php laravel laravel-5 laravel-filesystem