如何使用文件存储符号链接显示用户头像?

问题描述 投票:0回答:1

我正在尝试显示由用户上传的用户头像。该图像被保存在服务器上,但是每当我尝试显示该图像时,都会出现404 not found错误。

我正在使用此保存图像:

$path = $request->file('image')->store('avatars');

我已经使用php artisan storage:link命令作为documentation suggests创建了符号链接>

我的HTML:

@if(config('adminlte.usermenu_image'))
        <img src="{{ Auth::user()->adminlte_image() }}"
             class="user-image img-circle elevation-2"
             alt="{{ Auth::user()->name }}">
    @endif

我正在使用Laravel-adminLTE package,并使用下面的功能将图像URL发送到视图

public function adminlte_image()
{
    return Storage::url($this->avatar);
}

我的文件夹:

enter image description here

错误:

 http://localhost:8000/storage/avatars/S8Npk86Zun9FAYBREgxgOh9Ye6xiHVhyAmm3Vhb1.jpeg 404 (Not Found)

filesystems.php:

'disks' => [

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

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

我已经在这里找到了一些有关符号链接的问题,但我找不到答案。我显然在这里缺少任何东西,将不胜感激。

我正在尝试显示由用户上传的用户头像。该图像被保存在服务器上,但是每当我尝试显示该图像时,都会出现404 not found错误。我正在使用...

php laravel image symlink laravel-7
1个回答
0
投票

问题是我将映像存储在错误的磁盘中。我的filesystems.php指向/public目录。我将图像存储在/avatars中。

更改路径:

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.