Elgg  Version master
AddFileHelpTextHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Input;
4 
11 
21  public function __invoke(\Elgg\Event $event) {
22  $return = $event->getValue();
23  if (elgg_extract('input_type', $return) !== 'file') {
24  return;
25  }
26 
27  if (!elgg_extract('show_upload_limit', $return, true)) {
28  return;
29  }
30 
31  $help = elgg_extract('help', $return, '');
32 
33  // Get post_max_size and upload_max_filesize
35  $upload_max_filesize = elgg_get_ini_setting_in_bytes('upload_max_filesize');
36 
37  // Determine the correct value
38  $max_upload = min($upload_max_filesize, $post_max_size);
39 
40  $help .= ' ' . elgg_echo('input:file:upload_limit', [elgg_format_bytes($max_upload)]);
41 
42  $return['help'] = trim($help);
43 
44  return $return;
45  }
46 }
elgg_format_bytes(int $size, int $precision=2)
Format bytes to a human readable format.
Definition: output.php:103
if(!$php_log) $post_max_size
Definition: php.php:11
Adds help text to input/file.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
elgg_get_ini_setting_in_bytes(string $setting)
Returns a PHP INI setting in bytes.
Definition: elgglib.php:319
$help
Definition: field.php:27
$upload_max_filesize
Definition: php.php:12
__invoke(\Elgg\Event $event)
Add a help text to input/file about upload limit.
Models an event passed to event handlers.
Definition: Event.php:11