Hello to the community,
I'm building a portofolio page where upload images, i have created a class Portofolio where i save a Collection of a class Image.
class PortofolioPage
/**
* @ORM\OneToMany(targetEntity="App\Entity\Image", mappedBy="natureGallery", cascade={"persist"})
*/
private $natureGallery;
and my form type:
use Symfony\Component\Validator\Constraints\Image;
use Symfony\Component\Form\Extension\Core\Type\FileType;
->add('natureGallery', FileType::class, [
'multiple' => true,
'label' => 'form.natureGallery',
'mapped' => false,
'required' => false,
'constraints' => [
new Image([
'maxSize' => '5M',
])
],
])
without the constraints section i can upload images but i have a maxSize of 2M, if the contrainst section is active i get an error "This value should be of type string" ( i guess doesn't like whne i create the new Image it gets an array ) and if i deactivate the multiple stills doesn't allow me to upload a more than 2M.
I already modified my php.ini, post_max_size = 50M and upload_max_filesize = 50M and follow the documentation in https://symfony.com/doc/4.4/controller/upload_file.html and checked symfonycast but the solution eludes me.
Thanks for your time and happy coding
->add('natureGallery', FileType::class, [ 'multiple' => true, 'label' => 'form.natureGallery', 'mapped' => false, 'required' => false, 'constraints' => new All([ new Image([ 'maxSize' => '5M' ]) ]), ])
– Ernest Riccetto May 02 '20 at 09:00and tried in the class
@Assert\All(@Assert\Image(maxSize="5M"))