Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation issue on multiple file upload #2175

Closed
muradmustafayev opened this issue Aug 31, 2019 · 3 comments
Closed

Validation issue on multiple file upload #2175

muradmustafayev opened this issue Aug 31, 2019 · 3 comments

Comments

@muradmustafayev
Copy link

muradmustafayev commented Aug 31, 2019

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() ?>
@muradmustafayev muradmustafayev changed the title File upload Validation issue with AJAX Validation issue on multiple file upload Aug 31, 2019
@muradmustafayev
Copy link
Author

muradmustafayev commented Sep 1, 2019

Another problematic thing is empty spaces in validation rules. I mean:
mime_in[avatars, image/jpeg, application/pdf] - not working
mime_in[avatars,image/jpeg,application/pdf] - works

It'd be handy if remove spaces with str_replace or regex.
original code - $params = explode(',', $params); (file: CI4\system\Validation\FileRules.php)

@jim-parry jim-parry added this to the 4.0.0-rc.2 milestone Sep 8, 2019
@jim-parry
Copy link
Contributor

Spaces are not allowed in validation rules strings- that is not a bug.
https://codeigniter4.github.io/userguide/libraries/validation.html#available-rules
If you feel strongly about this, bring it up as an issue on its own, or raise it on the CI4 feature requests subforum.

@jim-parry jim-parry removed this from the 4.0.0-rc.2 milestone Sep 20, 2019
@jim-parry
Copy link
Contributor

Closed by #2265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants