Magento 2 admin supports multiple input types such as text box, radio button, dropdown, multi select boxes etc., the values of which stored and displayed in different forms of grids, forms, fields, images, etc.
Sometimes, while developing Magento 2 extensions, you may require to allow the admin to upload multiple files like icon image to show in the frontend or CSV with some zip codes to use the values somewhere in the extension. There are multiple file types such as PHP, XML, JPG, DOC, XLS, CSV and to allow the admin to upload files, you require to add file upload control in Magento 2 admin configuration.
However, the default Magento 2 does not have the facility to upload files for admin configuration. Thus, I have come up with the programmatic solution to add file upload control in Magento 2 admin configuration.
Programmatic Solution to Add File Upload Control in Magento 2 Admin Configuration
Add the below code in system.xml file at Meetanshi/Extension/etc/adminhtml/
<field id="custom_file_id" translate="label" type="Magento\Config\Block\System\Config\Form\Field\File" sortOrder="10"
showInDefault="1" showInWebsite="1" showInStore="1">
<label>File Upload Button</label>
Your file will be uploaded at magentoRoot/pub/media/MyUploadDir/filename.
That’s the only thing you need to do to add file upload control in admin configuration. You can also add custom image upload control in Magento 2 backend to allow only image file type uploads in stores configuration.
If you have queries, feel free to ask in the Comment section below.
I would be happy to solve your queries.
Do not forget to share the post with Magento Community via social media.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.