I know that the prefered way of uploading files is via Doctrine as explained in the book, but i need to save image data in an xml file and I also like constraint validator. Not much code has to be written for them. Anyway, I'm stuck on the Image constraint and i don't know am i doing everything the right way.
My validator.yml is as folows...
Frizer\AdminBundle\Entity\UploadedImage:
properties:
image:
- Image:
notFoundMessage: Image not uploaded
uploadErrorMessage: The image could not upload. Try again
uploadIniSizeErrorMessage: Image has to have more that 5M
mimeTypes: [image/jpeg, image/jpg, image/png]
mimeTypesMessage: Image has to be either jpg, jpeg or png format
minWidth: 500
minHeight: 500
minWidthMessage: Image has to be 500/500 px
minHeightMessage: Image has to be 500/500px
maxSize: 5M
maxSizeMessage: Image has to have more than 5M
validate() method accepts a UploadedImage object that has an $image property and a setter method for that property with a File type attribute. The constructor is as follows...
$uploadedImage = new UploadedImage();
$validator = $this->get('validator');
$errors = $validator->validate($uploadedImage);
var_dump($errors);
If i upload an image bigger that 5M, $errors is empty. Same thing if i don't upload anything. I searched trought the web and stack overflow with a tutorial on how to use constraints in file uploads but with no success. Could anyone explain what am I doing wrong?