Why my form dont display error (file size)

In my Symfony 6.4 project, I have a form with a file input and a maxSize set to 5M. On my web server in development mode (Symfony) with PHP 8.3.6, if I try to upload a file that’s 20M, the form displays an error message.

However, on my production server (Apache 2, PHP 8.3.6), the form does not display the error.

            ->add(
                'file',
                FileType::class,
                [
                    "required" => false,
                    "label" => "Ajout d'un document",
                    "multiple" => true,
                    "help" => "Formats : .pdf, .doc, .docx, .xlsx",
                    "constraints" => [
                        new All([
                            "constraints" => [
                                new File([
                                    "maxSize" => "5M",
                                    'maxSizeMessage' => "Le fichier est trop volumineux. La taille maximale autorisée est de 5 Mo.",
                                    'mimeTypes' => [
                                        'application/pdf',
                                        'text/csv',
                                        'application/msword',
                                        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                                        'application/vnd.ms-excel',
                                        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                                    ],
                                    'mimeTypesMessage' => "Seuls les formats : .pdf, .doc, .docx, .xlsx sont autorisés.",
                                ])
                            ]
                        ])
                    ],
                    "attr" => [
                        "accept" => ".pdf,.csv,.doc,.docx,.xls,.xlsx"
                    ]
                ]
            )

In my php.ini :

post_max_size = 20M
upload_max_filesize = 10M

I tried to change php.ini but no effect

It looks like you’re dealing with file upload issues related to the post_max_size and upload_max_filesize settings in PHP. Given the behavior you’re describing, here are a few things to check and address:

  1. Ensure PHP Configuration is Applied: After changing php.ini, make sure to restart your web server (Apache) to apply the new settings. You can check the effective values by creating a PHP file with phpinfo(); to confirm that post_max_size and upload_max_filesize are set correctly.
  2. Check Symfony Configuration: Symfony has its own configuration for handling file uploads, and it may be affected by PHP’s settings. Ensure there are no additional constraints or configurations in Symfony that might override the PHP settings.
  3. File Size Check in Symfony Form: Ensure that Symfony is configured to validate file size correctly. Since you’re setting maxSize in the form type, it should be working correctly if the PHP configuration allows for the upload.
  4. PHP Settings on Production Server: The production server may have different PHP settings compared to your development environment. Ensure post_max_size and upload_max_filesize are set correctly in the production php.ini and that they match or exceed your form constraints.
  5. Apache Configuration: Sometimes, Apache has its own configurations that could limit file sizes. Check the LimitRequestBody directive in your Apache configuration files (httpd.conf or .htaccess files) to ensure it isn’t limiting the file size.
  6. Symfony Error Handling: Make sure your Symfony application is set to display errors properly in production. Sometimes, error handling configurations in production may suppress or redirect error messages. Check the config/packages/prod/ directory for settings that might affect error display.
  7. Logs: Review both Symfony and Apache error logs for any clues on why the error might not be displayed. Logs can provide additional context or details on issues occurring during file uploads.
  8. Testing: Try uploading smaller files and gradually increase the size to ensure that the problem isn’t related to file handling in general but specifically to large files.

By verifying these settings and ensuring they are consistent between your development and production environments, you should be able to resolve the issue with file size validation not appearing as expected.