Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ghvinashvili's avatar

Laravel 5: mimes validator always returning errors even with right mime type.

@JeffreyWay mimes validator always returning errors even with right mime type, what can i do?

/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    return true;
}

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'title' => 'required',
        'body' => 'required',
        'date' => 'date',
        'tag_list' => 'required',
        'images' => 'required|mimes:jpeg',
    ];
}
0 likes
7 replies
ghvinashvili's avatar

i have enctype="multipart/form-data". i want multiupload file validation for this form. my form is here.

{!! Form::model($article = new \App\Article,['action' => 'ArticleController@store','files' => true]) !!}
    <div class="form-group">
        {!! Form::label('title', 'Title',['style' => 'font-weight: bold;']) !!}
        {!! Form::text('title', null, ['class' => 'form-control', 'placeholder' => 'Enter Title'] ) !!}
    </div>

    <div class="form-group">
        {!! Form::label('tag_list', 'Tags',['style' => 'font-weight: bold;']) !!}
        {!! Form::select('tag_list[]', $tags, null, ['class' => 'form-control','id'=>'select', 'multiple'] ) !!}
    </div>

    <div class="form-group">
        {!! Form::label('body', 'Body',['style' => 'font-weight: bold;']) !!}
        {!! Form::textarea('body', null, ['class' => 'form-control', 'placeholder' => 'Enter Title'] ) !!}
    </div>

    <div class="form-group">
        {!! Form::label('date', 'Date',['style' => 'font-weight: bold;']) !!}
        {!! Form::text('published_at', $article->published_at, ['class' => 'form-control','id' => 'date'] ) !!}
    </div>

    <div class="form-group">
        {!! Form::label('image_upload', 'Upload image',['style' => 'font-weight: bold;']) !!}
        {!! Form::file('images[]',['class'=>'form-control','id' => 'image_upload', 'multiple']) !!}
    </div>

    <div class="form-group">
        {!! Form::submit('Add article',['class' => 'form-control btn btn-primary']) !!}
    </div>
      
{!! Form::close() !!}
@if($errors->any())
    <ul class="alert alert-danger">
        @foreach($errors->all() as $error)
            <li>{{$error}}</li>
        @endforeach
    </ul>
@endif
kilrizzy's avatar

Just in case anyone runs into the issue I had, for some reason the javascript validation script I was using was actually stripping out the (enctype="multipart/form-data") line, so even though you have it set in your view just check your generated html and make sure

rargueso's avatar

Mime detection fails if there is no file uploaded. Check php.ini values relatives to file upload dirs & max sizes.

devEs's avatar

I know this thread is old, but this might help others who may stumbled on the same problem. I actually got the idea from what @rogrido said about checking your images/attachments as arrays. I am using "attachments[]" as input name by the way. And I got it working using this:

$this->validate(request(), [
        'attachments.*' => 'required|mimes:jpeg,png,pdf'
]);

using the dot(.) asterisk solved my problem.

4 likes
danjas's avatar

The * signifies "wilcard". if your event.target.files outputs as an array, then FILE_NAME.* would work because it's looking for every file in that array.

It worked for me. Thanks @devEs

Please or to participate in this conversation.