FounderStartup's avatar

How to catch the error Illuminate\ Http \ Exceptions\PostTooLargeException through validation ?

How to catch the error Illuminate\ Http \ Exceptions\PostTooLargeException through validation ?

If the user tries to upload some other kind of file then its able to validate but if the size is too large then it does not give error message ?

Controller

   if ($request->file('imageFile')) {

            $request->validate([
                'imageFile.*' => 'mimes:jpeg,jpg,png|max:10000'
              ]);

            $images = $request->file('imageFile');
            foreach ($images as $img) {
                $make_name = hexdec(uniqid()).'.'.$img->getClientOriginalExtension();
                Image::make($img)->save('upload/multipleimages/'.$make_name);
                Listingmultipleimage::insert([
                    'image' => $make_name,
                    'listingid' => $listid,
                    'created_at' => Carbon::now()
                ]);
            }
        }
0 likes
6 replies
Tray2's avatar

Not sure if that is possible, I think the servers limitations complains before it even gets that far.

I would start with ckecking the file size client side. Use a custom error view for it.

1 like
FounderStartup's avatar

@Tray2 The validation is not working in the controller for file size. Can you share any link to a solution for this issue ? Or any sample ?

FounderStartup's avatar

@Tray2 Seems to be a good solution. Thanks. But I am already having an "id" in the blade code.

    <div class="col-sm-12 col-md-12">
                                        <input type="file" name="imageFile[]" class="custom-file-input" id="files" multiple >
                                        <label class="custom-file-label" for="images">Choose Multiple Images At Once ( not one by one )</label>
                                    </div>

How can I use another id to use this script ?

Please or to participate in this conversation.