我正在使用 Symfony 2.1 将图像添加到默认的 fosUserBundle 用户实体。在我的实体之上,我有这个:
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="users")
*/
class User extends BaseUser
接下来是相关字段:
/**
* @ORM\Column(nullable=true)
* @Assert\File(maxSize="5M", mimeTypes={"image/gif", "image/jpeg", "image/png"})
*/
protected $promo;
我得到的错误是The mime type of the file is invalid (""). Allowed mime types are "image/gif", "image/jpeg", "image/png".
.
奇怪的是,当我 var_dump$this->promo->getClientMimeType()
我巧妙地得到image/jpeg
......所以由于某种原因验证器正在寻找错误的位置?
有谁知道可能导致这种情况的原因?