I'm trying to validate a file upload with 2 conditions:
Only allowed to upload image file or PDF file
Max width with Image file is 160px and no requirement with PDF file
I used "Constraints" of Symfony but when I upload a PDF file, it said that
This file is not a valid image.
Because I used both Assert\Image and Assert\File at the same time, so it will check whether the file is image or not first.
But What I want is that when I upload a file, it will check Assert\File first. If it's an image, then it will check Assert\Image. How can I do?
Here is my code at Entity:
/**
* @Vich\UploadableField(mapping="ad", fileNameProperty="imageFile")
* @var File
* @Assert\File(
* mimeTypes = {"application/pdf", "application/x-pdf", "image/png", "image/jpeg", "image/svg+xml"},
* mimeTypesMessage = "You can only be allowed to upload Image file or PDF file"
* )
* @Assert\Image(
* maxWidth = 160
* )
*/
private $image;