FileSize validation

Hi everyone. Anything wrong with this code?
It supposed to ensure that the uploaded file is not greater than ‘3MB’, but the error message appears even when the uploaded file is ‘2MB’.
I also tried COMPARE_GREATER… but it does the same.

Make sure your <form> tag is setup correctly to have enctype="multipart/form-data" set.

This can be done via doing

$this->Form->create($entity, ['type' => 'file']);

Then your submited file is of type \Psr\Http\Message\UploadedFileInterface and not just a string.

See Form - 4.x

Then your validation rule should be working fine.


I think the code has met those two. It even uploads some pictures as expected. But fails to deal with others.

The problem was the limitation of upload_max_filesize in php.ini to 2M.

Problem solved.