Solved: Disallowed File Type When Uploading Product Image in Magento 2
In the era of the visual trend, a product image is an essential component of the product page that can grab the buyer’s attention and exerts a real influence on their buying decisions. Potential buyers tend to deep-dive at various angles of images and get a better idea on how the product suits their utility.
While creating a product in Magento 2, the admin uploads product images to display on the frontend. Also, he replaces the product images as and when required.
During the product image upload or replace process, many Magento 2 store owners face a “Disallowed File Type” error. Usually, the error occurs when the wrong image file is uploaded. But sometimes, the “disallowed file type” error in Magento 2 occurs even when the image file type is correct.
You can’t leave the product page without images as it affects the shopping experience and conversions. Thus, I have come up with the solution to the error disallowed file type when uploading product image in Magento 2.
Solved: Disallowed File Type When Uploading Product Image in Magento 2
To solve the error, open Uploader.php file at vendor/magento/framework/File/
Replace the below line.
1 |
return $this->fileMime->getMimeType($this->_file['tmp_name']); |
With
1 |
return $this->_file['type']; |
That’s it. The disallowed file type error while uploading the product image gets solved just by replacing the code as above.
If you have a question regarding this error or the solution, feel free to ask in the Comment section below.
I would be happy to answer.
Thank you.
Related Post:
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
4 Comments
content images won’t upload, if if do this change. any solution for both?
Hello,
Please refer https://magento.stackexchange.com/questions/127586/magento-2-can-not-upload-product-images
Thanks
My images are SVG Format.
This solution didn’t work.
You need to add additional conditions for the SVG image format.