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_Laravel 5 - Fatal编程技术网

在视图文件-Laravel中显示存储在公用文件夹外的图像

在视图文件-Laravel中显示存储在公用文件夹外的图像,laravel,laravel-5,Laravel,Laravel 5,我在storage/app/uploads/image.jpg中有图像,我运行命令 Php artisan storage:link之后,在我的视图文件中,我使用了以下内容: img src={{ asset('storage/app/upload/image.jpg') }} 但是图像没有显示出来。我不想将图像放在公用文件夹中。任何帮助都是非常可观的。如果您不想将文件存储在存储/app/public(这就是存储:链接符号链接所做的),那么您需要创建一个路由: Route::get('show

我在storage/app/uploads/image.jpg中有图像,我运行命令
Php artisan storage:link
之后,在我的视图文件中,我使用了以下内容:

img src={{ asset('storage/app/upload/image.jpg') }}

但是图像没有显示出来。我不想将图像放在公用文件夹中。任何帮助都是非常可观的。

如果您不想将文件存储在
存储/app/public
(这就是
存储:链接
符号链接所做的),那么您需要创建一个路由:

Route::get('show-image', function() {
   $file = storage_path('app/upload/image.jpg');

   return response()->file($file);
})
  • 你说你在
    uploads
    文件夹中有图像,但是你的src说
    upload/
  • 您需要创建一个可以获取图像的路由

     Route::get('images/{filename}', function ($filename)
    {
     $path = app_path('upload') . '/' . $filename;
    
     $file = File::get($path);
     $type = File::mimeType($path);
    
     $response = Response::make($file, 200);
     $response->header("Content-Type", $type);
    
     return $response;
     })->name('route.name');
    
  • 然后在blade文件中,只需调用路由和图像的文件名(用逗号分隔)

    img src={{ route('route.name', 'image.jpg') }}
    

    在这种情况下,img src是什么?在这个伪示例中,是