如何在laravel中验证最大文件大小?

[英]How to validate on max file size in laravel?


I am trying to validate on a max file size of 500kb in laravel like this :

我试图在这样的laravel中验证最大文件大小为500kb:

$validator = Validator::make($request->all(), [
            'file'         => 'size:500',
]);

But this says that the file should be exactly 500 kb big. How can I edit this rule so that it gives an error when it is bigger than 500kb?

但是这说文件应该是500 kb大。如何编辑此规则,以便在大于500kb时出错?

Ive tried this :

我试过这个:

'file'         => 'size:>=500'
'file'         => 'size:max:500'

The documentation says nothing about this:

文档没有说明这一点:

size:value

大小:值

The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value. For files, size corresponds to the file size in kilobytes.

验证字段必须具有与给定值匹配的大小。对于字符串数据,value对应于字符数。对于数字数据,value对应于给定的整数值。对于文件,size对应于文件大小(以KB为单位)。

1 个解决方案

#1


52  

According to the documentation:

根据文件:

$validator = Validator::make($request->all(), [
    'file' => 'max:500000',
]);

The value is in kilobytes. I.e. max:10240 = max 10 MB.

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


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2016/05/25/75ba947a138a3ff66a07e42827c37f73.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号