0

I'm currently facing this issue where I want to use the max key when I upload a file. But then it returns a different message. The max key returns the uploaded message instead of the max message. I know I can use the uploaded key but this key is for validation when the file was not successfully uploaded. [Other reference].

Code

public function rules()
{
    return [
        'image' => 'required|max:2048|file|mimetypes:image/jpg,image/jpeg,image/png'
    ];
}

public function messages()
{
    return [
        'image.max' => 'The image file size must not be greater than 2Mb.'
    ];
}

Expected

The image file size must not be greater than 2Mb.'

Result

The image failed to upload.

4
  • image.max will only return if the uploaded file size is greater than 2MB not for other wise any other reason! You need to dig deeper and find out why upload is unsuccessful ! Commented Oct 18, 2023 at 10:35
  • Maybe you have to update upload_max_filesize , as @OMiShah said the error is not related to your max validation Commented Oct 18, 2023 at 12:08
  • the server is completely ditching the body after it hits a certain size, so to PHP there is no file uploaded since it was outside the POST max size or upload max size, etc etc Commented Oct 18, 2023 at 14:00
  • I am uploading a 2.3Mb file so I don't think it has to do with my configuration. Commented Oct 19, 2023 at 9:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.