php - Symfony Sonata Media - Upload an Image Validation -




i trying add image user. problem having when click upload select image, files considered. of @assert\image application go form page if add non-image file.

  • is there way restrict types can chosen in upload window?
  • or, how can @ least display message before user click submit when format chosen?

enter image description here

class user     {         /**          * @var int          *          * @orm\column(name="id", type="integer")          * @orm\id          * @orm\generatedvalue(strategy="auto")          */         private $id;          /**          * @var string          *          * @orm\column(name="name", type="string", length=1000, nullable=true)          */         private $name;          /**          * @assert\image(          * maxsize = "5m"          * )          * @var gallery          * @orm\onetoone(targetentity="application\sonata\bundle\mediabundle\entity\media", cascade={"persist","remove"})          */         private $image;       // ...etc     } 

myform.php

  $builder         ->add('name',   texttype::class)         ->add('image', "sonata_media_type", array(             'context' => 'image',             'provider' => 'sonata.media.provider.image',             'label' => "image",             'required' => true         )); 

config

 [![contexts:         default:  # default context mandatory             providers:                 - sonata.media.provider.image                 - sonata.media.provider.file             formats:                 icon: { width: 100, quality: 100}                 thumbnail: { width: 150, quality: 100}                 preview: { width: 300, quality: 100}         image:             providers:                 - sonata.media.provider.image             formats:                 icon: { width: 100, quality: 100}                 thumbnail: { width: 150, quality: 100}                 preview: { width: 300, quality: 100}     providers:         image:             service:    sonata.media.provider.image             resizer:    sonata.media.resizer.simple # sonata.media.resizer.square             allowed_extensions: \['jpg', 'png', 'jpeg'\]             allowed_mime_types: \['image/pjpeg', 'image/jpeg', 'image/png', 'image/x-png'\]][1]][1] 





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -