vanker's avatar

Limit file upload size

I searched the docs and found max rule:

$validation = Validator::make(Input::all(),[
            'name'          => 'required',
            'dob'          => 'required',
            'group'         => 'required',
            'active'         => 'required',
            'photo'          => 'max:2000000|mimes:jpeg,jpg,png,bmp'
         ]);

The code says that it should limit a file to a maximum of 2000000 bytes = 2mb and the mimes being jpg,png and bmp. However only the mimes one work, I could upload a 5mb files without problem, what I'm missing? or did I misunderstood the MAX rule?

Ty!

0 likes
5 replies
bytefury's avatar
Level 15

its not in bytes but kilobytes. so try 2000.

2 likes
vanker's avatar

It worked, I feel so ashamed of myself :/, However, there is no default error message?

bytefury's avatar

Why would there be an error message? it probably assumes you want to keep a higher limit. If you are talking about default validation error message then it does have a default error message. You can check all default validation error messages in app/lang/en/validation.php

bashy's avatar

Depends if you're showing the error message anywhere. There will be a default for if the file is over the size limit.

"max" => array(
  "numeric" => "The :attribute may not be greater than :max.",
  "file" => "The :attribute may not be greater than :max kilobytes.",
  "string" => "The :attribute may not be greater than :max characters.",
  "array" => "The :attribute may not have more than :max items.",
 ),

You could probably use the "image" validation rule as well?

1 like
vanker's avatar

Yeah, but nvm, I forgot to put $errors->first() on my view :), thanks for the answers!, Awesome forum aswell!

Please or to participate in this conversation.