我想使用文件验证器来限制文件输入的mime类型.不幸的是,从未使用过此约束,并且所有文件都被接受
namespace WNC\SoldierBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* WNC\SoldierBundle\Entity\Soldier
*
* @ORM\Table(name="soldier")
* @ORM\Entity(repositoryClass="WNC\SoldierBundle\Entity\SoldierRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Soldier
{
/**
* @var string $picture
* @Assert\Image()
* @ORM\Column(name="picture", type="string", length=255)
*/
private $picture;
/**
* @var string $file
*
* @Assert\Image()
* @Assert\NotBlank()
*/
public $file;
public function getAbsolutePath()
{
return null === $this->picture ? null : $this->getUploadRootDir().'/'.$this->picture;
}
public function getWebPath()
{
return null === $this->picture ? null : $this->getUploadDir().'/'.$this->picture;
}
protected function …Run Code Online (Sandbox Code Playgroud)