How to Add File Upload Control in Magento 2 Admin Configuration

How to Add File Upload Control in Magento 2 Admin Configuration

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/

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.

Thank you.

Related: How to Allow File Attachment in WYSIWYG in Magento 2

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 8 Reviews)

He has been with Meetanshi for more than two years now as a Magento developer. A silent guy whom you can always find solving clients' issues, is an avid reader too.

Leave a reply:

Your email address will not be published.