微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 如何在Laravel中验证最大文件大小?

我试图在Laravel中验证最大文件大小为500kb:

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

但是这说文件应该是500kb大.如何编辑此规则,以便在大于500kb时返回错误

我试过这个:

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

文档没有说明这一点:

size:value

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

解决方法:

根据文件

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐