How to check the maximum file size 500KB

How to check the size of downloaded files at 500Kb? I'm fine, but it fails:

public function rules()
    {
        return [
...
           'myfile'
            ], 'file', 'extensions' => 'pdf, jpg', 'maxSize' => 4096000, 'tooBig' => 'Limit is 500KB' ],
        ];
    }
+4
source share
1 answer

You have indicated the wrong one maxSize.

From official docs:

The maximum number of bytes required for the downloaded file. The default values ​​are null, which means no restrictions. Note. The size limit also depends on the 'upload_max_filesize' INI and the hidden field 'MAX_FILE_SIZE' value.

See also $ tooBig for a customized message for a file that is too large.

500 kilobytes - 500 * 1024 bytes = 512,000 bytes.

public function rules()
{
    return [
        ['myfile', 'file', 'extensions' => 'pdf, jpg', 'maxSize' => 512000, 'tooBig' => 'Limit is 500KB'],
    ];
}

'maxSize' => 500 * 1024, , - ( ).

:

+11

All Articles