Jim Peeters Jim Peeters - 5 months ago 60
PHP Question

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 :

$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?

Ive tried this :

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

The documentation says nothing about this:


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.


According to the documentation:

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