Magento – Magento 2 : admin file field max upload size

adminfile uploadmagento2

I'm trying to restrict the weight of the uploaded file in admin, I found the 'maxFileSize' in Magento documentation but it's not working :

$fieldset->addField(
  'files',
  'file',
  [
    'name' => 'file',
    'label' => __('File'),
    'title' => __('File'),
    'maxFileSize' => 2097152,
    'required' => false,
    'note' => 'File size must be less than 2 Mb.'
  ]
);

Thanks !

Best Answer

I think I would use php.ini instead.

To ensure that file uploads work correctly, the post_max_size directive should be a little larger than the upload_max_filesize. For example, the following settings demonstrate how to set a file upload limit to 20 megabytes:

upload_max_filesize = 20M
post_max_size = 21M