Skip to content

Commit

Permalink
UploadControl: addRule() checks upload_max_filesize limit
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 2, 2020
1 parent 04eebfa commit ec59537
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Forms/Controls/UploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public function addRule($validator, $errorMessage = null, $arg = null)
} elseif ($validator === Form::MIME_TYPE) {
$this->control->accept = implode(', ', (array) $arg);
} elseif ($validator === Form::MAX_FILE_SIZE) {
if ($arg > Forms\Helpers::iniGetSize('upload_max_filesize')) {
$ini = ini_get('upload_max_filesize');
trigger_error("Value of MAX_FILE_SIZE ($arg) is greater than value of directive upload_max_filesize ($ini).", E_USER_WARNING);
}
$this->getRules()->removeRule($validator);
}
return parent::addRule($validator, $errorMessage, $arg);
Expand Down
10 changes: 10 additions & 0 deletions tests/Forms/Controls.UploadControl.loadData.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,13 @@ test(function () { // validators on multiple files

Assert::true(Validator::validateImage($input));
});


test(function () { // validators on multiple files
$form = new Form;
$input = $form->addUpload('invalid1');

$rules = iterator_to_array($input->getRules());
Assert::count(2, $rules);
Assert::same($form::MAX_FILE_SIZE, $rules[1]->validator);
});

0 comments on commit ec59537

Please sign in to comment.