Magento 2. How to upload images to pub/media
-
01-10-2020 - |
سؤال
Problem
I have a $fieldset
. What arguments should I give to ->addField
method to create an input field, that loads image to $_FILES
?
What was done
For now I have an input field.
Created by
$fieldset->addField('image',
'image',
[
'title' => __('Image'),
'label' => __('Image'),
'name' => 'image',
'note' => 'Allow image type: jpg, jpeg, gif, png',
]
);
But the $_FILES
is empty, when I checking it in controller execute()
method.
Additional information
$fieldset
arguments was taken from this example.
المحلول
Go to file app/code/Vendor/Modulename/Block/Adminhtml/Modulename/Edit/Form.php
there is 'enctype' => 'multipart/form-data'
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data']]
);
لا تنتمي إلى magento.stackexchange