Home » wp-content » themes » functions.php » Not Allowed to Upload This File Type in WordPress? Fix It

Not Allowed to Upload This File Type in WordPress? Fix It

You drag a file into the Media Library or a block, and WordPress stops it with “Sorry, you are not allowed to upload this file type.” Older WordPress versions showed the same block as “Sorry, this file type is not permitted for security reasons.” It hits fonts, CSV imports, SVG logos, files for a download plugin, and sometimes even a file type WordPress normally accepts.

The fix depends on which of two checks failed. Either the extension is not on the allowed list, or the extension is allowed but the file content does not look like that type. I will show you how to tell which one it is, then fix it with a small must-use plugin instead of turning the check off.


During every upload, _wp_handle_upload() calls wp_check_filetype_and_ext(). If that returns no extension or no MIME type, and the user does not have the unfiltered_upload capability, the upload is rejected with this message.

wp_check_filetype_and_ext() fails a file in two situations:

  • The extension is not in get_allowed_mime_types(). That list comes from wp_get_mime_types() and passes through the upload_mimes filter. SVG is not in the core list, and swf and exe are always removed.
  • The extension is allowed, but PHP’s fileinfo extension reads the file content and reports a different MIME type. Core treats that mismatch as dangerous and sets both the extension and the type to false.

There is a third, quieter case. Users without the unfiltered_html capability also lose htm|html and js from the list. So an Editor can see this error for a file an Administrator uploads without trouble.


First, list what WordPress allows for a real user. Pass a user ID, because WP-CLI runs without a logged-in user and would hide the unfiltered_html types:

wp eval 'print_r( get_allowed_mime_types( 1 ) );'

You get an array of extension patterns like jpg|jpeg|jpe mapped to MIME types. If your extension is not in any of the keys, you have the first case. Replace 1 with the ID of the user who hit the error.

If the extension is there, copy the file to the server (SFTP into /tmp is fine) and ask WordPress what it thinks of it:

wp eval 'var_dump( wp_check_filetype_and_ext( "/tmp/products.csv", "products.csv" ) );'
file --mime-type -b /tmp/products.csv

If the var_dump shows ext and type as false while the extension is on the allowed list, the content check failed. The file command prints the type the content was detected as. Note it down, you need it in Step 3.

💡 If var_dump returns a valid type on the command line but the browser upload still fails, check which user is uploading. A role without unfiltered_html gets a shorter list than the admin.


Back up your site first. Then create a must-use plugin so the change survives theme switches and updates. Make the file wp-content/mu-plugins/upload-types.php (create the mu-plugins folder if it does not exist):

<?php
/**
 * Plugin Name: Extra upload types
 */

add_filter( 'upload_mimes', function ( $mimes, $user ) {
	// extension (or ext1|ext2) => MIME type the file really has
	$mimes['woff2'] = 'font/woff2';
	$mimes['json']  = 'application/json';

	return $mimes;
}, 10, 2 );

Use the MIME type that file --mime-type reported for your file, not one copied from a random list. If the two do not match, the content check can still reject the file.

Must-use plugins load automatically, so there is nothing to activate. Run the print_r command from Step 1 again and your extension should now be in the list. If it is not, another plugin may be filtering upload_mimes after yours. Give yours a later priority, for example 99 instead of 10.

Want a type only for administrators? The filter gets a $user argument (an ID, a WP_User or null), so you can check user_can( $user, 'manage_options' ) before adding it. When $user is null, use current_user_can() instead.

New to mu-plugins and custom code? I explain the options in how to add custom PHP code to WordPress.

See also  Sorry, You Are Not Allowed to Access This Page in WordPress (Fix)

This is the case where the extension is allowed but fileinfo disagrees, for example a .csv that is detected as text/plain. Adding the extension again does nothing, because the extension was never the problem.

The wp_check_filetype_and_ext filter runs at the very end of the check and receives the detected type as $real_mime (added in WordPress 5.1). Approve only exact extension and detected-type pairs you trust. Add this to the same mu-plugin file:

add_filter( 'wp_check_filetype_and_ext', function ( $data, $file, $filename, $mimes, $real_mime ) {
	if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) {
		return $data; // core already accepted it
	}

	// extension => [ MIME to store, detected types you accept ]
	$fixes = array(
		'csv' => array( 'text/csv', array( 'text/plain', 'application/csv' ) ),
	);

	$ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );

	if ( isset( $fixes[ $ext ] ) && in_array( $real_mime, $fixes[ $ext ][1], true ) ) {
		$data['ext']  = $ext;
		$data['type'] = $fixes[ $ext ][0];
	}

	return $data;
}, 10, 5 );

Replace the csv example with your own extension and the detected type from Step 1. The extension must also be on the allowed list, from core or from Step 2.

This keeps the check working for everything else. A PHP file renamed to .csv is not detected as plain text or CSV, so it is still rejected.

If $real_mime is always false, the PHP fileinfo extension is probably missing. Check with php -m | grep fileinfo, and make sure the PHP version your site runs on has it, not only the CLI one.


On multisite, extensions are also limited by the Upload file types field in Network Admin > Settings. It is stored in the upload_filetypes network option as a space-separated list, and anything not in it is dropped from the allowed types.

wp site option get upload_filetypes
wp site option update upload_filetypes "jpg jpeg png gif webp pdf csv woff2"

The first command prints the current list. Copy that output into the second command and add your extensions to the end, or you will drop types your sites already use.


Many answers online tell you to add this to wp-config.php:

define( 'ALLOW_UNFILTERED_UPLOADS', true );
not allowed to upload this file type wp config 1 - Not Allowed to Upload This File Type in WordPress? Fix It
Where it goes in wp-config.php: above the “That’s all, stop editing!” line

It works, but look at what it does. In map_meta_cap(), the unfiltered_upload capability is denied to everyone unless this constant is true. With it set, any user whose role has that capability skips the file type check completely. On multisite, only Super Admins get it.

That means an administrator account, or a stolen admin session, can upload any file, including PHP. I only use it to confirm the type check is the cause. Add it, try the upload once, then remove the line and fix the real cause with Step 2 or Step 3.

💡 Even with the constant set, users whose role lacks unfiltered_upload still see the error. Fix their uploads with the filters above.


SVG is a common file behind this error, and it is missing from the core list on purpose. An SVG is XML that can carry JavaScript, so adding 'svg' => 'image/svg+xml' through upload_mimes lets anyone who can upload media store a script on your domain.

If you need SVG uploads, use a plugin that sanitizes each SVG on upload, and limit it to trusted roles. As of 2026-11-26 core still does not include SVG in its default MIME list, so check that the plugin you pick is maintained.

If the upload fails with a different message, it is a different problem. Size limits are covered in increasing the upload file size limit, and a missing PHP temp directory in Missing a temporary folder.


TL;DR: run get_allowed_mime_types() and wp_check_filetype_and_ext() with WP-CLI to see whether the extension is missing or the content check failed. Add missing extensions with the upload_mimes filter, accept known content mismatches with the wp_check_filetype_and_ext filter, and keep ALLOW_UNFILTERED_UPLOADS for a one-time test only.

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended