简体   繁体   English

索纳塔媒体捆绑和约束

[英]Sonata Media Bundle and constraints

I'm using SonataMediaBundle so my users can associate images to products. 我正在使用SonataMediaBundle,以便我的用户可以将图像与产品关联。

The thing is, if they try to upload a file bigger than upload_max_filesize it throws an exception. 关键是,如果他们尝试上传大于upload_max_filesize的文件,则会引发异常。 I tried using Symfony's constraints but it doesn't work. 我尝试使用Symfony的约束,但是不起作用。 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 它甚至没有考虑到该约束,因为如果我尝试上传大于maxSize且小于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 ? 您是否尝试在php.ini设置upload_max_filesize More instructions . 更多说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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