我在尝试上传图片时需要帮助 CodeIgniter 4

I need help when I try to upload an image CodeIgnite4

我在尝试上传图片时需要帮助

我收到这个错误,我不明白为什么 avatar is not a valid uploaded file.

我在控制器中的代码

规则:

'avatar' => [
                'rules' => 'required|uploaded[avatar]|max_size[avatar,1024]|ext_in[avatar,jpg,jpeg,png]',

                'errors' => [
                    'required' => lang('Core.Auth.Error.required'),
                    ]
            ],

上传:

if (!$this->validate($rules)) {
            $data['validation'] = $this->validator;
        } else {

                $avatar = $this->request->getFile('avatar');
                   $newName = $avatar->getRandomName(); 
                   $avatar->move(WRITEPATH.'uploads', $newName);
                   $filepath = base_url()."/selfie/".$newName;

我的php.ini

upload_max_filesize = 1G

post_max_size = 1G

memory_limit = 1G

来自 CodeIgniter 文档:

The uploaded rule fails if the name of the parameter does not match the name of any uploaded files.

如果不能满足此规则,将显示您发布的确切错误消息

仔细检查您的 HTML <input> 标签并确保此标签的 name 属性和传递给 uploaded 规则的名称相同,例如:

// In the HTML
<input type="file" name="avatar">

// In the controller
$this->validate([
    'avatar' => 'required|uploaded[avatar]|max_size[avatar,1024]|ext_in[avatar,jpg,jpeg,png]'
]);