0

First of all, I apologize for my English...

I'm having a problem with my music upload. I found thanks to Symfony Doc, how upload file and I set up my picture upload successfully. However I found a problem with my music upload, my dump in my controller indicates to me an error, and tells me that my file exceeds 2M, yet in my file php.ini, upload_max_filesize is defined at 256M. My code to upload my music it's same as the picture.

My Code :

namespace App\Form;

use App\Entity\Artist;
use App\Entity\Category;
use App\Entity\Music;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\FileType;

class MusicType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('title')
            ->add('description')
            ->add('picture', FileType::class, [
                'mapped' => false,
                'required' => false,
                'constraints' => [
                    new File([
                        'maxSize' => '8M',
                        'mimeTypes' => [
                            'image/jpeg',
                            'image/png',
                            'image/webp'
                        ]
                    ])
                ],
                'attr' => [
                    'accept'=>'.jpg, .jpeg, .png, .gif'
                ]
            ])
            ->add('music', FileType::class, [
                'mapped' => false,
                'constraints' => [
                    new File([
                        'maxSize' => '256M',
                        'mimeTypes' => [
                            'application/octet-stream',
                            'audio/mpeg',
                            'audio/mp3'
                        ]
                    ])
                ]
            ])

I've been looking for a soluce, but all the results refer me back to https://symfony.com/doc/current/reference/constraints/File.html#maxsize

If you are ideas, I'm interested.

Weyss
  • 3
  • 2

1 Answers1

0

First you need to check the post_max_size in php.ini.

upload_max_filesize is the limit of any single file. post_max_size is the limit of the entire body of the request, which could include multiple files.

Make sure that post_max_size >= upload_max_size

See previous answers about this.

PHP post_max_size overrides upload_max_filesize

Ikenna Emman
  • 153
  • 1
  • 8
  • Thank for your answer. I checked my file php.ini and it's ok. I think the problem lies in Symfony, because when I upload just a picture, I haven't an error like with music. – Weyss Aug 16 '20 at 07:19
  • It's ok, I didn't understand had to put a php.ini file at the root Symfony project :) – Weyss Aug 17 '20 at 09:29