I want to set different max file sizes for different file types, like:
Right now, my validator only allows 10 MB for all file types:
$validator = Validator::make($request->all(), [
'file' => 'required|max:10000|mimes:jpg,jpeg,png,gif,mp4',
]);
How can I set different max file sizes for different file types?
You can solve this question with the using if condition rule. I know, it is not best practice but it could solve your issue.
$default_max_value = 10000;
if($request->hasFile('file') && $request->get('file')->getClientOriginalExtension() == 'mp4'){
$default_max_value = 50000;
}
$validator = Validator::make($request->all(), [
'file' => 'required|max:'.$default_max_value.'|mimes:jpg,jpeg,png,gif,mp4',
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With