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

GotExx's avatar

Image validation fail

Hello, I can't understand why my image verification doesn't work... I have already set up an image upload system in another part of my project that works perfectly...

                        <form method="POST" action="{{ route('storePost') }}">
                            @csrf
                            <div class="form-group">
                                <label class="sr-only" for="content">post</label>
                                <textarea class="form-control" id="content" name="content" rows="1" placeholder="What are you thinking?" required></textarea>
                            </div> 
                            <div class="btn-group mr-2">
                                <button type="submit" class="btn btn-suspect">{{ __('app.share') }}</button>
                            </div>
                            <input type="file" style="display: none;" id="attachement" 
                                   name="attachement" oninput="showFile()" aria-describedby="attachement"
                                   accept="image/png, image/jpeg, image/jpeg, image/gif">
                            <label for="attachement"><i class="fa fa-lg fa-picture-o" aria-hidden="true"></i></label>
                            <span id="attachement-text"></span>
                            <div class="btn-group float-right">
                                <select class="custom-select" name="game">
                                    <option value="" selected>{{ __('post.related-game') }}</option>
                                    @foreach($games as $game)
                                    <option value="{{ $game->id }}">{{ $game->name }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </form>

and my controller

        $validatedData = $request->validate([
            'content' => 'required|max:250',
            'game' => 'nullable|integer',
            'attachement' => 'nullable|image|mimes:jpg,png,jpeg,gif|max:5120'
        ]);

        dd("ok");

I always get the error:

  • The attachement must be an image.
  • The attachement must be a file of type: jpg, png, jpeg, gif.
0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

Your form must have enctype="multipart/form-data" attribute

Please or to participate in this conversation.