zendframework/zend-validator

MimeType validator doesn't work for multiple files.

gavinlimely opened this issue · 4 comments

Hi,

The IsImage validator doesn't work with html5 file inputs that have the multiple attribute assigned.

It validates the first file file, then gives the error :

Warning: finfo_file(): 557 is not a valid file_info resource in vendor/zendframework/zend-validator/src/File/MimeType.php on line 387

Warning: finfo_close(): 557 is not a valid file_info resource in vendor/zendframework/zend-validator/src/File/MimeType.php on line 388

Ideally, the behaviour is that it won't pass validation unless all of the files are images?

Thanks

Ideally, the behaviour is that it won't pass validation unless all of the files are images?

A validator validates always one value.

But you can combine the Callback and the IsImage validator. Loop over the value and check every file.

Ok thank you for the quick response. It does seem like a work around though, seen as the file validators are built to work with the $_FILES array?

@gavinlimely

the file validators are built to work with the $_FILES array?

No, not the entire $_FILES array. Only the format (tmp_name and name) and for each only one value.
(You can use the validators also for files that have not been uploaded.)

My suggestion: an equivalent for multiple files like the Explode validator.

This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at laminas/laminas-validator#19.