سؤال

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 مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top