How validating the upload files size by up to 500Kb? I'm doing well, but it's not working out:
public function rules()
{
return [
...
'myfile'
], 'file', 'extensions' => 'pdf, jpg', 'maxSize' => 4096000, 'tooBig' => 'Limit is 500KB' ],
];
}
Using Plugin MethodGo to your WordPress Dashboard → Plugins → Add new, search “Increase Max Upload Filesize”, then Install and Activate the plugin. Once installed, go to plugin settings and simply enter the value for upload size. Click the Save Changes button to apply the new upload size.
You specified wrong maxSize
.
From offical docs:
The maximum number of bytes required for the uploaded file. Defaults to null, meaning no limit. Note, the size limit is also affected by 'upload_max_filesize' INI setting and the 'MAX_FILE_SIZE' hidden field value.
See also $tooBig for the customized message for a file that is too big.
500 kilobytes is 500 * 1024 bytes = 512 000 bytes.
public function rules()
{
return [
['myfile', 'file', 'extensions' => 'pdf, jpg', 'maxSize' => 512000, 'tooBig' => 'Limit is 500KB'],
];
}
Also you can specify it like 'maxSize' => 500 * 1024
, this is more readable and you don't have to do any calculations (for more complex measure units this is preferable option).
Useful links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With