Skip to content

Validation issue on multiple file upload #2175

Description

@muradmustafayev

In validation getFile() returns NULL in CI4\system\Validation\FileRules.php if send multiple file to validate. Should check if multiple or single upload
Same issue on other validation methods where is used getFile()

public function max_size(string $blank = null, string $params, array $data): bool
	{
		// Grab the file name off the top of the $params
		// after we split it.
		$params = explode(',', $params);
		$name   = array_shift($params);
		$file = $this->request->getFile($name); // returns NULL but files exist in $this->request. Should check if multiple or single upload
		if (is_null($file))
		{
			return false;
		}
		return $params[0] >= $file->getSize() / 1024;
	}

My Controller method

public function upload()
    {
        $validation =  \Config\Services::validation();
        $validation->setRules([
                'avatars' => 'max_size[avatars,2048]|mime_in[avatars,image/jpeg]|ext_in[avatars,jpeg,jpg]',
            ]
        );

        $validation->withRequest($this->request)->run();
        dd($validation->getErrors());
    }

HTML code

<?= form_open_multipart('admin/post/upload') ?>
        <input type="file" name="avatars[]" multiple>
        <input type="submit">
    <?= form_close() ?>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions