I'am trying to add a field to upload image for specific user. I add field but problem is when I try save User. Image isn't uploaded and I got exception that $_FILES is empty. I followed these instructions:

Magento2 : Admin module Image upload code to display form

How to successfully upload image?

有帮助吗?

解决方案

look like, the enctype for the form still not set, try update the code

  $form = $this->_formFactory->create();

to be like this :

$form = $this->_formFactory->create(
    [
    'data' => [
               'id' => 'id_form',
               'method' => 'post',
               'enctype' => 'multipart/form-data'
              ]
    ]
);

....
....
....

$form->setUseContainer(true);
$this->setForm($form);

you can reference to this link : Magento 2 Fail to change form encoding method to enctype='multipart/form-data'

hope this can solve your problem

许可以下: CC-BY-SA归因
scroll top