Laravel 从存储文件夹返回图像
我在存储文件夹中有一些图像。我希望得到他们的回应,并向我的用户展示 我的尝试: 我使用以下代码,但它返回Laravel 从存储文件夹返回图像,laravel,Laravel,我在存储文件夹中有一些图像。我希望得到他们的回应,并向我的用户展示 我的尝试: 我使用以下代码,但它返回NULL: // All images are in the storage/app/users/{id}/document folder $path = storage_path( 'app/users/'.$id . '/document'); if (!File::exists($path)) { abort(404); } $file = File::files($path)
NULL
:
// All images are in the storage/app/users/{id}/document folder
$path = storage_path( 'app/users/'.$id . '/document');
if (!File::exists($path)) {
abort(404);
}
$file = File::files($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
输出:空
- 我的错在哪里
- 有更好的解决办法吗
返回存储::文件('users/'.$id./document'))
laravel中存储文件的默认路径为storage/app/public
,默认情况下,您不应设置此路径,并且您的路径位于此路径之后,laravel默认从该路径开始
并记住添加使用light\Support\Facades\Storage代码>
在你班的最上面你不知道文件名吗?@akshaypjoshi我正在使用file:files
,这将导致所有文件都被返回。Laravel版本?@WahyuKristianto6.4.0版本
。