【问题标题】:Limit the image size on laravel request post限制 laravel 请求帖子上的图像大小
【发布时间】:2021-06-14 00:51:38
【问题描述】:

大家好,我需要限制图片的大小,不是文件的大小,而是宽度和高度,到目前为止我有这个:

public function rules()
{
    if(request()->isMethod('put')) // could be patch as well
    {
         // Update rules here - Don't require image here
         return [
            'name' =>                'required',           
            'code' =>                'required|regex:/^#?(([a-f0-9]{3}){1,2})$/i',
            'image' =>               'required|image|max:8192',
        ];

    }
}

【问题讨论】:

  • 我相信您正在寻找dimensions 验证规则。

标签: php laravel post request


【解决方案1】:

是的,有可能

'image' => 'required|image|dimensions:max_width=300,max_height=300'

如文件所述

验证中的文件必须是符合尺寸的图片 规则参数指定的约束:

'头像' => '尺寸:min_width=100,min_height=200'

可用的约束有:min_width、max_width、min_height、max_height、width、 高度,比例。

参考:https://laravel.com/docs/8.x/validation#rule-dimensions

【讨论】:

    猜你喜欢
    • 2011-01-22
    • 1970-01-01
    • 2012-06-02
    • 2012-01-05
    • 2020-09-09
    • 2011-12-01
    • 1970-01-01
    相关资源
    最近更新 更多