Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Symfony version(s) affected

6.4

Description

When validating file uploads using the FileType with multiple => true, an UnexpectedValueException is thrown from Symfony\Component\Validator\Constraints\FileValidator at line 120.

Current Behavior:
The exception occurs in FileValidator at this condition:

if (!\is_scalar($value) && !$value instanceof FileObject && !$value instanceof \Stringable) {
    throw new UnexpectedValueException($value, 'string');
}

Expected Behavior:
The validator should properly handle multiple file uploads without throwing an exception. When multiple => true is set, the input should be processed as an array of files rather than a single value.

How to reproduce

Code Example:

$builder->add('files', FileType::class, [
    'constraints' => [
        new File([
            'maxSize' => '1024k',
            'extensions' => ['jpg','jpeg','png']
        ], binaryFormat: true)
    ],
    'required' => false,
    'multiple' => true
]);

Possible Solution

No response

Additional Context

This appears to be incorrect behavior specifically when validating file inputs with the multiple option enabled. The validator should account for array values when dealing with multiple file uploads.

You must be logged in to vote

If you want to add a constraint for each of an array items you need to use All: https://symfony.com/doc/current/reference/constraints/All.html

Replies: 1 comment

Comment options

If you want to add a constraint for each of an array items you need to use All: https://symfony.com/doc/current/reference/constraints/All.html

You must be logged in to vote
0 replies
Answer selected by saulsluz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
2 participants
Converted from issue

This discussion was converted from issue #61816 on September 23, 2025 07:59.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.