Laravel文件大小验证返回错误,无论文件大小如何

时间:2019-02-13 03:36:30

标签: php laravel

我正在尝试使用验证器来验证提交的文件:

def gil_pnms(polys, scores, thresh=0.7):
scores = np.array(scores)
order = np.argsort(scores)[::-1]
cdef:
    int i = 0
    int j = 0
    int num_polys = polys.shape[0]
    float inS = -1.
    np.ndarray[float, mode="c", ndim=2] ps = polys.astype(np.float32)
    np.ndarray[float, mode="c", ndim=2] inter_areas = np.zeros((num_polys, num_polys), dtype=np.float32)
    np.ndarray[float, mode="c", ndim=1] areas = np.zeros(num_polys, dtype=np.float32)

for i in prange(num_polys,nogil=True):
    for j in prange(i, num_polys):
        with gil:
            a = <float*> np.PyArray_DATA(ps[i])
            b = <float*> np.PyArray_DATA(ps[j])
        areas[i] = wrap_aip_d.intersection(a, a)
        inS = wrap_aip_d.intersection(a, b)
        inter_areas[i, j] = inS
        inter_areas[j, i] = inS

keep = []
while order.size > 0:
    i = order[0]
    keep.append(i)
    ovr = inter_areas[i][order[1:]] / (areas[i] + areas[order[1:]] - inter_areas[i][order[1:]])
    inds = np.where(ovr <= thresh)[0]
    order = order[inds + 1]
return keep,areas,inter_areas

无论我尝试提交的文件大小如何,无论是3MB还是50KB,它始终会返回相同的错误:$validatedData = $request->validate(['profilePhoto' => 'required|image|size:256']); 。 我的php设置:{"message":"The given data was invalid.","errors":{"profilePhoto":["The profile photo must be 256 kilobytes."]}}post_max_size: 64M

2 个答案:

答案 0 :(得分:3)

  

size:value =>验证中的字段必须具有与给定值匹配的大小。

使用max代替size

$validatedData = $request->validate(['profilePhoto' => 'required|image|max:256']);

请注意,该值以千字节为单位。即最大:10240 =最大10 MB。

答案 1 :(得分:0)

编辑您的尺寸:256到256000,如下所示将解决此问题。

$validatedData = $request->validate(['profilePhoto' => 'required|image|size:256000']);