How do I fix "Sorry, this file type is not permitted for security reasons"

When I try to upload any PNG file, I get the following error message:

I have no plugin or anything installed, that could cause this. I even added the following line in order to fix this:

define('ALLOW_UNFILTERED_UPLOADS', true);

Since it is a local installation, security is not an issue. But still this didn't fix my problem. Any ideas what could cause this problem?

Topic uploads images Wordpress

Category Web


WordPress has a logic to check the file content. If it doesn't match to the ext of the file, it may not accept the upload.


Please insert the script below to function.php in your theme:

 function custom_myme_types($mime_types){
  $mime_types['images'] = "png/jpg";
  return $mime_types;
}
add_filter('upload_mimes', 'custom_myme_types', 1, 1);

Try using the plugin WP Extra file types . Install this plugin in your wordpress site and you will be provided with a variety of extension option . You can select whatever extensions you want like png and upload the png file. This plugin will automatically support your files. You can also add new type of file which is not in the library and edit . This is a very easy way to upload whichever files you want.


Did you add this line correctly? define('ALLOW_UNFILTERED_UPLOADS', true);

Because I faced the same issue fee days back and I added that code in my wp-config file right above where it says /* That's all, stop editing! Happy blogging. */

After uploading the file, I removed this line from wp-config file.


This error is thrown in _wp_handle_upload function. As you see from line above it will be thrown when WordPress can not figure it out which file type or file extension you are trying to upload. Try to debug $type and $ext variables to find out why your .png file is not recognized correctly.

My guess is that your webserver/WordPress is not recognizing png mime type correctly. Thats why $type variable is false|null|0.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.