- // Cap the upload size according to the PHP limit.
- $max_filesize = Bytes::toInt(file_upload_max_size());
- if (!empty($settings['max_filesize'])) {
- $max_filesize = min($max_filesize, Bytes::toInt($settings['max_filesize']));
+ if ($upload) {
+ // Cap the upload size according to the PHP limit.
+ $max_filesize = Bytes::toInt(file_upload_max_size());
+ if (!empty($settings['max_filesize'])) {
+ $max_filesize = min($max_filesize, Bytes::toInt($settings['max_filesize']));
+ }
+ // There is always a file size limit due to the PHP server limit.
+ $validators['file_validate_size'] = [$max_filesize];