# Image file validation

**URL:** <https://discourse.cakephp.org/t/image-file-validation/5326>\
**Category:** Need Help\
**Created:** [November 28, 2018, 4:29am UTC](https://discourse.cakephp.org/t/image-file-validation/5326 "2018-11-28T04:29:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kuniko](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kuniko](https://discourse.cakephp.org/u/Kuniko)\
**Post date:** [November 28, 2018, 4:29am UTC](https://discourse.cakephp.org/t/image-file-validation/5326/1 "2018-11-28T04:29:55Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Graziel](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Graziel](https://discourse.cakephp.org/u/Graziel)\
**Post date:** [November 28, 2018, 6:09am UTC](https://discourse.cakephp.org/t/image-file-validation/5326/2 "2018-11-28T06:09:36Z")

</div>

there is set of available rules you can use in validation:  
[https://api.cakephp.org/3.6/class-Cake.Validation.Validation.html](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#_fileSize)  
[https://api.cakephp.org/3.6/class-Cake.Validation.Validation.html#\_mimeType](https://api.cakephp.org/3.6/class-Cake.Validation.Validation.html#_mimeType)

---

<div class="post-metadata">

**Author:** ![Kuniko](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kuniko](https://discourse.cakephp.org/u/Kuniko)\
**Post date:** [November 29, 2018, 5:28am UTC](https://discourse.cakephp.org/t/image-file-validation/5326/3 "2018-11-29T05:28:55Z")

</div>

Thank you for your reply!

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

I thank you a lot!
