Skip to content

Commit d826b1a

Browse files
committed
Helpers: added iniGetSize()
1 parent d24449c commit d826b1a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/Forms/Form.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,7 @@ public function validateMaxPostSize(): void
497497
if (!$this->submittedBy || !$this->isMethod('post') || empty($_SERVER['CONTENT_LENGTH'])) {
498498
return;
499499
}
500-
$maxSize = ini_get('post_max_size');
501-
$units = ['k' => 10, 'm' => 20, 'g' => 30];
502-
if (isset($units[$ch = strtolower(substr($maxSize, -1))])) {
503-
$maxSize = (int) $maxSize << $units[$ch];
504-
}
500+
$maxSize = Helpers::iniGetSize('post_max_size');
505501
if ($maxSize > 0 && $maxSize < $_SERVER['CONTENT_LENGTH']) {
506502
$this->addError(sprintf(Validator::$messages[self::MAX_FILE_SIZE], $maxSize));
507503
}

src/Forms/Helpers.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,15 @@ private static function prepareAttrs(?array $attrs, string $name): array
217217
}
218218
return [$dynamic, '<' . $name . Html::el(null, $attrs)->attributes()];
219219
}
220+
221+
222+
/** @internal */
223+
public static function iniGetSize(string $name): int
224+
{
225+
$value = ini_get($name);
226+
$units = ['k' => 10, 'm' => 20, 'g' => 30];
227+
return isset($units[$ch = strtolower(substr($value, -1))])
228+
? (int) $value << $units[$ch]
229+
: (int) $value;
230+
}
220231
}

0 commit comments

Comments
 (0)