【问题标题】:How to show image in storage?如何在存储中显示图像?
【发布时间】:2021-02-02 14:18:58
【问题描述】:

我是这样存储文件的。

public function update(Request $request)
{
   $user = auth()->user();
   $path = null;
   if ($request->hasFile('image'))
   {
        $file = $request->file('image');
        $nane = time();
        $extension = $file->getClientOriginalExtension();
        $fileName = $nane . '.' . $extension;
        $path = $file->storeAs('images/users', $fileName, 'public');
    }
    $user->image = $path;
    $user->save();
    return redirect()->back();
  }

我想显示一张图片,但没有显示。

<img src="{{ asset('storage/') . auth()->user()->image }}" id="dialog" class="img-fluid rounded-circle cursor-pointer">

我确实跑了。

php artisan storage:link

文件系统.php

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

    's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => env('AWS_URL'),
    ],

],

但我看到了这个演示。

我在 Laravel 存储中上传了用户头像。如何访问它们并在视图中呈现它们?

【问题讨论】:

  • 在问题的config 目录中添加您的filesystems.php 文件。
  • 删除符号链接并再次运行php artisan storage:link
  • @ElektaKode 我更新了 mmy 帖子

标签: laravel


【解决方案1】:

您的图片名称不在资产函数中。 此外,由于您的 url 格式是在 filesystems.php 文件中定义的,因此无需在资产帮助程序中写入“storage/”。

你应该写:

<img src="{{ asset(auth()->user()->image) }}" id="dialog" class="img-fluid rounded-circle cursor-pointer">

【讨论】:

    猜你喜欢
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 2011-11-24
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多