Image file validation


#1

Hello! I am a Japanese programmer and I hope you read my English.

I use bake command and make car photo stock system. And I would like to make these validation of image file. The variable name is “car_photo_name” And I hope to use a parameter:size and type.

If I don’t use cakePHP, I coded below:
if ($car_photo_name_type == ‘image/jpeg’){-----}
if ($car_photo_name_size < 0){------}

I hope to know on function validationDefault, how I code above ‘if’ statement.
If you know that, would you please reply?
Thank you!


#2

there is set of available rules you can use in validation:
https://api.cakephp.org/3.6/class-Cake.Validation.Validation.html

what you need are:
https://api.cakephp.org/3.6/class-Cake.Validation.Validation.html#_fileSize
https://api.cakephp.org/3.6/class-Cake.Validation.Validation.html#_mimeType


#3

Thank you for your reply!

I added ‘use Cake\Validation\Validation;’ and the functions are now moving collectly.

I thank you a lot!