Skip to content

Commit

Permalink
Change "max_size" option units from MiB to B
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitro-N committed Jul 26, 2022
1 parent 7ef48ed commit 64b6505
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getConfigTreeBuilder()
->end()
->scalarNode('max_size')
->defaultValue(\PHP_INT_MAX)
->info('Set max_size to -1 for gracefully downgrade this number to the systems max upload size.')
->info('Maximum file size in bytes. Set max_size to -1 for gracefully downgrade this number to the systems max upload size.')
->end()
->scalarNode('max_files')
->defaultValue(\PHP_INT_MAX)
Expand All @@ -94,7 +94,7 @@ public function getConfigTreeBuilder()
->prototype('scalar')->end()
->end()
->scalarNode('max_size')
->info('Set max_size to -1 for gracefully downgrade this number to the systems max upload size.')
->info('Maximum file size in bytes. Set max_size to -1 for gracefully downgrade this number to the systems max upload size.')
->end()
->scalarNode('max_files')
->info('Set max files.')
Expand Down
5 changes: 2 additions & 3 deletions EventListener/MaxSizeValidationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ public function onValidate(ValidationEvent $event)
$config = $event->getConfig();
$file = $event->getFile();

if ($file->getSize() > $config['max_size'] * (1024 * 1024)) {
$fileSizeInMegaBytes = round($file->getSize() / (1024 * 1024));
if ($file->getSize() > $config['max_size']) {
throw new ValidationException(
'error.maxsize', ['filesize' => $fileSizeInMegaBytes, 'maxFilesize' => $config['max_size']]
'error.maxsize', ['filesize' => $file->getSize(), 'maxFilesize' => $config['max_size']]
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/translations/messages+intl-icu.en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
error:
invalid_type: You can't upload files of this type
maxsize: 'File is too big ({filesize} MB). Max filesize: {maxFilesize} MB'
maxsize: 'File is too big ({filesize} bites). Max filesize: {maxFilesize} bites'
2 changes: 1 addition & 1 deletion Resources/translations/messages+intl-icu.ru.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
error:
invalid_type: Неверный формат файла
maxsize: Файл слишком большой ({filesize} MB). Максимальный допустимый размер файла {maxFilesize} MB
maxsize: Файл слишком большой ({filesize} байт). Максимальный допустимый размер файла {maxFilesize} байт

0 comments on commit 64b6505

Please sign in to comment.