繁体   English   中英

我正在尝试在我的 Laravel 8 应用程序中上传个人资料图片。 但是,我不断收到“尝试读取数组上的属性“图像””错误

[英]I am trying to upload a profile image within my Laravel 8 application. I however keep getting "Attempt to read property "image" on array" error

我正在尝试在我的 Laravel 8 应用程序中保存/上传个人资料图像。 我在 Laravel Fortify 中使用库存 controller "UpdateUserProfileInformation.update" 但是我一直收到此错误

ErrorException 尝试读取数组上的属性“图像”

看法

...
<form method="POST" action="{{ route('user-profile-information.update') }}">
                    @csrf
                    @method('PUT')
...
<input class="file-upload d-none" type="file" accept="image/*" id="image" name="image" />
...

Controller

public function update($user, array $input)
    {
        ...
            $fileName = time().'.'.$input['image'];
            $input->image->move(public_path('uploads'), $fileName);
    ...

显然我的问题是我正在尝试保存一个数组,但我不知道如何隔离这个单个文件。

处理表单中的文件时,您应该添加一个 enctype

<form enctype="multipart/form-data" method="post" action="">

使用文件时,您需要在表单标签中添加enctype="multipart/form-data"

代替

<form method="POST" action="{{ route('user-profile-information.update') }}">

<form method="POST" action="{{ route('user-profile-information.update') }}" enctype="multipart/form-data">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM