awarren's avatar

Mulitiple File Upload Mime Validation Issue

I have a form setup to accept multiple files. Validation is done using a form request. Only PDF file types should be accepted. The validator is working but I can't get messages to display. I've tried every combination I can think of in both request messages() and in the language file. The other error messages work fine.

Here is the validation rule:

'agreement.*' =>'mimes:pdf',

Thanks in advance.

0 likes
6 replies
awarren's avatar

This the the form input:

<div class="col-md-12">
    <div class="form-group">
        <p>Participation Agreement</p>
        {!! Form::label('Upload the participation agreement (optional)') !!}
        {!! Form::file('agreement[]', ['multiple' => 'multiple']); !!}
    </div>
</div>

This is the errors partial:

@if( $errors->any() )
        <div class="col-11">
            <ul class="alert alert-danger">
            @foreach($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
            </ul>
        </div>
@endif

All the inputs work and all the other error messages display. Multiple files will upload. If files contain a non-pdf file, the form redirects without saving the record or files which is expected.

awarren's avatar

An update:

Today something started happening that wasn't happening before. The only thing I've done is a composer update. During the update I noticed quite a lot of updates happening, especially with Symfony.

Today, I started seeing a brief Laravel error message and then the page would redirect. I managed to snag a screenshot before the refresh and what I saw was this: Exception in Store.php line 262: Serialization of 'Illuminate\Http\UploadedFile' is not allowed. That wasn't happening yesterday. I found this thread which gave me a clue - https://laracasts.com/discuss/channels/requests/serialization-of-symfonycomponenthttpfoundationfileuploadedfile-is-not-allowed?page=1.

I overloaded $dontFlash in my form request like this: protected $dontFlash = ['agreement'];. The message went away and I'm now seeing the mimetype error messages as expected. Turns out there was nothing wrong with my validation setup.

I'm not sure exactly what changed in the cores but it's working now. It'd be nice to understand why there was no system error before I ran composer update. Is this perhaps a bug that crept in with a Symfony update and should be reported for @TaylorOtwell in the Laravel tracker?

awarren's avatar

Update 3:

I believe this issue has to do with recursively calling array_filter and PHP 7.x. The recursive code in Illuminate/Http/RedirectResponse.php predates PHP 7.x. Someone tested in both 5.x and 7.x and confirmed the issue is only appearing in 7.x. More info here.

Please or to participate in this conversation.