【问题标题】:How to display in a blade view images stored in a external storage?如何在刀片视图中显示存储在外部存储器中的图像?
【发布时间】:2019-05-09 03:35:39
【问题描述】:

我想使用外部存储来保存我的图像并在刀片中显示它们

我创建了一个自定义文件系统,其中存在我的图像(在本例中是我的文档文件夹),但是当我尝试在刀片中显示图像时,它们没有显示

我的自定义文件系统:

'custom' => [
    'driver' => 'local',
    'root' => 'C:/Users/my name/Documents',
    'url' => 'http://localhost/halo/public/prueba',
    'visibility' => 'public',
],

简单的刀片

<img src="{{ Storage::disk('custom')->url("pantalla.png") }}">

还有路线

Route::get('/prueba', function () {
    return view('prueba');
});

http://localhost/halo/public/prueba 显示损坏的图像图标

源代码显示如下:

<img src="C:/Users/my name/Documents/pantalla.png">

【问题讨论】:

  • 您只能访问 Web 服务器 Web 根文件夹中的文件。
  • 嗯,这是一个巨大的限制
  • 限制可能是,但它对安全至关重要。否则人们可以从你的系统中访问任何东西,他们需要的是一条路径,我相信你不想让你的私人内容像那样可用。

标签: php laravel image storage external


【解决方案1】:

使用此代码,图像使用刀片文件显示在 html 视图中,但图像来自特定项目目录。假设存储在 uploads/admin 目录中的图像和图像来自 uing session 或者我们可以说是中间件

在刀片文件中添加这些代码

<img src="{{url('/uploads/admin/'.\Session::get('admin')->profile_image)}}" alt="profile image">

【讨论】:

    猜你喜欢
    • 2019-06-12
    • 2021-09-21
    • 1970-01-01
    • 2019-03-15
    • 2022-07-08
    • 2021-02-04
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    相关资源
    最近更新 更多