Skip to content

Commit 9d62255

Browse files
committed
UploadControl: addRule() checks upload_max_filesize limit
1 parent 7b5575f commit 9d62255

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Forms/Controls/UploadControl.php

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public function addRule($validator, $errorMessage = null, $arg = null)
110110
} elseif ($validator === Form::MIME_TYPE) {
111111
$this->control->accept = implode(', ', (array) $arg);
112112
} elseif ($validator === Form::MAX_FILE_SIZE) {
113+
if ($arg > Forms\Helpers::iniGetSize('upload_max_filesize')) {
114+
$ini = ini_get('upload_max_filesize');
115+
trigger_error("Value of MAX_FILE_SIZE ($arg) is greater than value of directive upload_max_filesize ($ini).", E_USER_WARNING);
116+
}
113117
$this->getRules()->removeRule($validator);
114118
}
115119
return parent::addRule($validator, $errorMessage, $arg);

tests/Forms/Controls.UploadControl.loadData.phpt

+10
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,13 @@ test(function () { // validators on multiple files
234234

235235
Assert::true(Validator::validateImage($input));
236236
});
237+
238+
239+
test(function () { // validators on multiple files
240+
$form = new Form;
241+
$input = $form->addUpload('invalid1');
242+
243+
$rules = iterator_to_array($input->getRules());
244+
Assert::count(2, $rules);
245+
Assert::same($form::MAX_FILE_SIZE, $rules[1]->validator);
246+
});

0 commit comments

Comments
 (0)