Fileupload Validation of fileSize in CakePHP 4

How can i validate the filesize of a uploaded file?

i have this rule

$validator->add(‘profilepicture_file’,‘file’,
[‘rule’=>[‘mimeType’,[‘image/gif’,‘image/png’]],‘message’=>(‘Bitte nur Dateien vom Typ jpg, jpeg, gif oder png verwenden.’)],
[‘rule’=>[‘fileSize’,’<=’,‘1 MB’],‘message’=>
(‘Die Datei darf nicht größer als 5MB sein.’)]
);

The mimeType validation works, but not the validatation of the fileSize.
Can someone help me?
regards
Dirk

You can’t just chain multiple extra parameters onto the add call. You need to call add separately for each rule.

1 Like