Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 从存储文件夹返回图像_Laravel - Fatal编程技术网

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版本?@WahyuKristianto
6.4.0版本