php - codeigniter 4 multiple file validation

Solution:

I am not sure about this either as I am having this problem too. But, I am logging (via print_r) the call to $this->request->getFileMultiple('my_file_name_here') and noticed when I submitted my form without having a file attached, a file object was created (hence returning TRUE - I think). The object has all the properties empty, except the error property is set to 4 and if this maps to PHP's File Upload Errors, it means no file was uploaded.

I wonder if the object is created specifically because of this error?

Here is the code from my logging when I submit the form with no file attached.

(
    [0] => CodeIgniter\HTTP\Files\UploadedFile Object
        (
            [path:protected] => 
            [originalName:protected] => 
            [name:protected] => 
            [originalMimeType:protected] => 
            [error:protected] => 4
            [hasMoved:protected] => 
            [size:protected] => 0
            [pathName:SplFileInfo:private] => 
            [fileName:SplFileInfo:private] => 
        )

)

I honestly don't know how to (or not to) check for an if($this->request->getFileMultiple('my_file_name_here')) if it is going to always be true whether a file is attached or not.

I could be totally wrong in all this. I am up for any help and suggestions.

If this is totally wrong or not in accord with the site rules, take it down by all means.

Answer

Solution:

Just use getFiles().

$this->request->getFiles('my_file_name_here')

Source