B
B
BonBon Slick2018-09-21 11:57:01
symfony
BonBon Slick, 2018-09-21 11:57:01

How to validate the number of files?

* @var File|UploadedFile
     *
     * @Assert\NotNull()
     * @Assert\NotBlank()
     * @Assert\Image(
     *      detectCorrupted=true,
     *      mimeTypes={"image/png", "image/jpg", "image/jpeg"},
     * )
     * @Assert\File(
     *     maxSize="8M",
     * )
     */
    public $imageFile;

    /**
     * self constructor.
     *
     * @param UploadedFile $imageFile
     */
    public function __construct(UploadedFile $imageFile)
    {
        $this->imageFile = $imageFile;
    }

However, if nothing comes, then this DTO is valid, and then it gives an error in the code after validation
$filesMeta = \json_decode($request->request->get('ашдуы')); 
       foreach ($filesMeta as $imageMetaData) {
...
Warning: Invalid argument supplied for foreach()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2018-09-21
@BonBonSlick

This won't help?
https://symfony.com/doc/current/reference/constrai...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question