I have an Entity Media which have protected File value
<?php
namespace Chiave\MediaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* @ORM\Table(name="media")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class Media
{
...
/**
* @Assert\File(
* maxSize="5M"
* )
*/
protected $file;
Then i extend this class in my AppBundle because I need only images to get pass validation
<?php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="image")
*/
class Image extends \Chiave\MediaBundle\Entity\Media
{
/**
* @Assert\Image()
*/
protected $file;
}
Also i have Form Type for this which looks like this
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use AppBundle\Form\ImageType as ImageType;
class POIType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
...
->add('images', 'collection', [
'type' => new ImageType,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'label' => ' ',
]);
}
My problem is that validation didn`t work. I can upload image yes, but i can also upload PHP file or... pretty much everything. Any ideas? I will be very grateful.
Thanks in advance.