简体   繁体   中英

Sonata Media Bundle and constraints

I'm using SonataMediaBundle so my users can associate images to products.

The thing is, if they try to upload a file bigger than upload_max_filesize it throws an exception. I tried using Symfony's constraints but it doesn't work. It doesn't even take that constraint in account, as it doesn't fire if I try to upload a file bigger than maxSize and smaller than upload_max_filesize

use Symfony\Component\Validator\Constraints as Assert;

/**
 * @Assert\Image(
 *     maxSize="2M"
 * )
 * @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media")
 */
protected $image;

Surely, there must be a way to achieve such a basic thing?

Did you try setting upload_max_filesize in php.ini ? More instructions .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM