我正在尝试在 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.
最佳答案
根据 the documentation :
$validator = Validator::make($request->all(), [
'file' => 'max:500000',
]);
该值以千字节为单位。 IE。 max:10240
= 最大 10 MB。
关于php - 如何在 Laravel 中验证最大文件大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37432641/