Skip to content

Fix "Sorry, you are not allowed to upload this file type" in WordPress

Find out why WordPress rejects a file with "Sorry, you are not allowed to upload this file type." and fix it without weakening upload security. You will check which file types your site allows, see what type WordPress detects inside the file, and add the extension you need with a small must-use plugin.

You drop a file into the WordPress Media Library and get “Sorry, you are not allowed to upload this file type.” instead of an upload. WordPress refused it for one of two reasons: the extension is not on the site’s allow-list, or the content does not look like that extension. The fix is to find out which check failed, then allow the type for administrators with a small must-use plugin. It usually happens with a .json export, a web font, a CSV that worked last month, or a file someone renamed. Before WordPress 5.9, the same refusal read “Sorry, this file type is not permitted for security reasons.”

What you’ll accomplish

  • Know which of the two checks rejected your file, using one WP-CLI command instead of guesswork.
  • See the file type WordPress detects inside the file, and compare it with what the extension claims.
  • Allow a new extension for administrators only, in a file that survives theme changes and updates.
  • Handle the harder case where the extension is allowed but the content check still says no.
  • Understand why the ALLOW_UNFILTERED_UPLOADS shortcut is risky, and the one situation where it is acceptable.

Prerequisites

You need an administrator account and a way to add files to wp-content/, through SFTP, your host’s file manager, or SSH. The commands run through WP-CLI, the wp program that most managed and cPanel hosts install for SSH users. Every fix also works without it, but the checks are much faster with it.

The steps assume WordPress 6.x on PHP 8. The content check described here arrived with the WordPress 5.0.1 security release, and the $real_mime argument used in step 6 has existed since 5.1. On a Multisite network (several sites sharing one WordPress install), you also need super admin access for step 5.

How it works

Every upload path in WordPress ends in the same core function, wp_check_filetype_and_ext(). That includes the Media Library, the block editor and the REST API, the web interface that apps and scripts use to send files. It returns a file extension and a MIME type, the standard label such as text/csv or image/png that tells software what a file contains. If either comes back empty, the upload stops with the error, as the diagram shows. The block editor also runs check 1 in the browser before it sends anything. That is why its version of the message starts with the file name, as in “report.json: Sorry, you are not allowed to upload this file type.”

Flow of a WordPress upload through wp_check_filetype_and_ext. Check 1 looks up the file extension in the upload_mimes allow-list. Check 2 uses fileinfo to read the real type from the file content. A no at either check leads to the error Sorry, you are not allowed to upload this file type. An administrator with the unfiltered_upload capability can bypass the rejection and the file is saved anyway.

Check 1 is the extension allow-list. WordPress builds the list with get_allowed_mime_types(). It starts from the built-in list in wp_get_mime_types(), removes .exe and .swf for everyone, and removes .html and .js for users without the unfiltered_html capability. A capability is a named permission attached to a role. Plugins and themes can then change the list through the upload_mimes filter. Common types such as .json, .svg, .woff and .woff2 are not on the default list.

Check 2 compares the content with the extension. When the PHP fileinfo extension is loaded, WordPress reads the first bytes of the file and asks what type they look like. This is called the “real” MIME type. If it disagrees with the type the extension claims, the file is refused, even when the extension is allowed. Core forgives a few common mismatches:

  • Text formats such as .csv, .txt and .vtt may be detected as text/plain.
  • Audio and video only need the major type to match, so a .mov saved as .mp4 passes.
  • A generic binary result such as application/octet-stream is accepted when the extension claims an application/, audio/ or video/ type.
  • Images whose extension is wrong but whose content is a valid image are renamed with the correct extension, not rejected.

Anything outside those rules must match exactly. A .docx renamed to .pdf fails. A .json file that an older fileinfo build reports as text/plain fails, because application/json is not on the text list. A .woff2 font that an older build reports as application/octet-stream fails, because font/woff2 is not an application, audio or video type.

The bypass is the unfiltered_upload capability. When the checks fail but the user has this capability, WordPress saves the file anyway. Administrators only get it when ALLOW_UNFILTERED_UPLOADS is set in wp-config.php, and on Multisite only super admins get it. More on that trade-off at the end.

SVG files get their own treatment on this site, because the risk there is script hidden inside the image. If that is your file type, read our guide on enabling SVG uploads in WordPress safely instead.

Step-by-step

1. Confirm the error is about the type, not the size. A file that is too big produces a message naming upload_max_filesize, or “The uploaded file exceeds” some limit. If you see that instead, the fix is in PHP, and our guide on raising upload_max_filesize on cPanel covers it. A 403 Forbidden page means a firewall on the server blocked the request before WordPress ran, which is a different problem.

2. Check whether the extension is on the allow-list. Run this over SSH from the site’s folder. Pass --user with an administrator’s login, because the list depends on who is asking.

wp eval 'print_r( get_allowed_mime_types() );' --user=admin

Example output (trimmed):

Array
(
    [jpg|jpeg|jpe] => image/jpeg
    [gif] => image/gif
    [png] => image/png
    [webp] => image/webp
    [txt|asc|c|cc|h|srt] => text/plain
    [csv] => text/csv
    [vtt] => text/vtt
    [pdf] => application/pdf
    [zip] => application/zip
)

Look for your extension in the keys on the left. If it is missing, check 1 is failing and you can go to step 4. If it is present, check 2 is the likely cause, so continue with step 3. Without SSH, you can confirm the same thing by trying the upload with a tiny test file of that type.

3. Run the exact core check against your file. Copy the rejected file to the server, then pass its full path and name to the same function WordPress uses.

wp eval 'print_r( wp_check_filetype_and_ext( "/home/example/report.json", "report.json" ) );' --user=admin

Example output for a rejected file:

Array
(
    [ext] =>
    [type] =>
    [proper_filename] =>
)

Empty ext and type values reproduce the error. Now see what the content looks like to a type detector.

file --mime-type /home/example/report.json

Example output:

/home/example/report.json: text/plain

The file command uses the system’s copy of libmagic, the library that recognises file types from their first bytes. PHP ships its own copy, which can be older or newer. To see exactly what PHP detects, ask it directly.

php -r 'echo (new finfo(FILEINFO_MIME_TYPE))->file("/home/example/report.json"), PHP_EOL;'

It prints one line such as text/plain or application/json. On cPanel, run the PHP binary for your site’s version, for example /opt/cpanel/ea-php82/root/usr/bin/php, so the result matches what the website uses. If the detected type differs from the type you expect for the extension, check 2 is failing and you need both step 4 and step 6.

4. Add the extension with a must-use plugin. A must-use plugin is a PHP file in wp-content/mu-plugins/ that WordPress loads on every request. It cannot be switched off from the admin, and theme changes do not remove it. Create the folder if it does not exist, then create wp-content/mu-plugins/upload-types.php with this content.

<?php
/**
 * Plugin Name: Extra upload types
 * Description: Allows JSON and WOFF2 uploads for administrators only.
 */

add_filter( 'upload_mimes', function ( $mimes, $user = null ) {
    $can = $user ? user_can( $user, 'manage_options' ) : current_user_can( 'manage_options' );
    if ( $can ) {
        $mimes['json']  = 'application/json';
        $mimes['woff2'] = 'font/woff2';
    }
    return $mimes;
}, 5, 2 );

Replace the two lines inside the if with the types you need, using the official MIME type for each extension. The manage_options check limits the new types to administrators. Editors and authors keep the default list, which is the safe choice for anything you have not reviewed. Priority 5 makes the entry exist before Multisite applies its own filter, which matters in step 5.

Confirm WordPress loaded the file.

wp plugin list --status=must-use --fields=name,status

Example output:

+--------------+----------+
| name         | status   |
+--------------+----------+
| upload-types | must-use |
+--------------+----------+

Run the command from step 2 again. Your extension now appears in the list with the MIME type you set.

5. On Multisite, add the extension to the network setting. A network keeps its own list of permitted extensions, and WordPress removes anything that is not on it. In the Network Admin, open Settings > Network Settings, find Upload file types under Upload Settings, add your extension to the space-separated list, and save. With WP-CLI, read and extend the same value.

wp site option get upload_filetypes

Example output from a network created before WordPress 6.6:

jpg jpeg png gif webp mov avi mpg 3gp 3g2 midi mid pdf doc ppt odt pptx docx pps ppsx xls xlsx key mp3 ogg flac m4a wav mp4 m4v webm ogv flv

Networks created on WordPress 6.6 or later start with every core extension on this list, so yours may be much longer. Either way, json and woff2 are missing until you add them.

wp site option update upload_filetypes "$(wp site option get upload_filetypes) json woff2"

WP-CLI answers Success: Updated 'upload_filetypes' site option. The network list only keeps extensions that WordPress already knows, which is why step 4 still has to add them.

6. Fix a mismatched detected type, only if step 3 showed one. When the extension is allowed but the detected type disagrees, add a second filter to the same must-use plugin. It acts only on files core has rejected, only for named extensions and detected types, and only after it verifies the content.

add_filter( 'wp_check_filetype_and_ext', function ( $data, $file, $filename, $mimes, $real_mime ) {
    // Leave files that core already accepted alone.
    if ( $data['ext'] && $data['type'] ) {
        return $data;
    }
    $ext     = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
    $allowed = get_allowed_mime_types();

    // JSON reported as plain text: accept it only if it parses as JSON.
    if ( 'json' === $ext && 'text/plain' === $real_mime && isset( $allowed['json'] )
        && null !== json_decode( file_get_contents( $file ) ) ) {
        return array( 'ext' => 'json', 'type' => 'application/json', 'proper_filename' => false );
    }

    // WOFF2 reported as a generic binary: accept it only if it starts with the font signature.
    if ( 'woff2' === $ext && 'application/octet-stream' === $real_mime && isset( $allowed['woff2'] )
        && 'wOF2' === file_get_contents( $file, false, null, 0, 4 ) ) {
        return array( 'ext' => 'woff2', 'type' => 'font/woff2', 'proper_filename' => false );
    }

    return $data;
}, 10, 5 );

The isset( $allowed[...] ) tests keep step 4 in charge of who may upload these types. Resist the popular snippet that returns the extension’s type for every file. That turns the content check off for all uploads, which is the one protection that catches a script renamed to look like a document.

Validate it works

Test through the same code path the Media Library uses. wp media import runs the full upload checks and creates a real attachment, so it proves the fix end to end.

wp media import /home/example/report.json --user=admin

Example output:

Imported file '/home/example/report.json' as attachment ID 4187.
Success: Imported 1 of 1 items.

If it fails, the output names the reason.

Warning: Unable to import file '/home/example/report.json'. Reason: Sorry, you are not allowed to upload this file type.
Error: No items imported.

Then check the other side of the rule. Run the same import with an editor’s login, for example --user=editor. It should still fail, which shows the new type is limited to administrators. Finally, upload the file once in the browser from Media > Add Media File (called Add New Media File before WordPress 6.8) and confirm it appears in the library. Delete the test attachments when you are done.

Troubleshooting

The extension is in the list, but the upload still fails. Run step 3 again. The detected type almost always explains it. A CSV exported with unusual encoding or stray binary bytes can be detected as application/octet-stream, which a text/ type does not accept. Resave the file as UTF-8 CSV from your spreadsheet tool before you write any filter.

The type was added, then disappears again. Another plugin filters upload_mimes later and replaces the list. Security plugins and some hosts’ own must-use plugins do this on purpose. Find every filter with this command from the site’s folder.

grep -rl "upload_mimes" wp-content/plugins wp-content/mu-plugins wp-content/themes --include=*.php

It prints one file path per match. Check each plugin’s settings for an upload restriction before you edit anything. Your host’s plugin may be a deliberate policy, so ask them before you work around it.

It works for you but not for a colleague. The list depends on the user. Step 4 limits new types to manage_options, and core only allows .html and .js for users with unfiltered_html. Run step 2 with their login to see their list.

The block editor says “report.json: Sorry, this file type is not supported here.” That message comes from the block you dropped the file on, not from the upload check. An Image block only takes images and an Audio block only takes audio. Use a File block, or upload through the Media Library first.

Nothing changed after you created the file. Make sure the file sits directly in wp-content/mu-plugins/, not in a subfolder, and starts with <?php. WordPress does not load must-use plugins from subfolders. The wp plugin list command in step 4 shows whether it loaded.

When this is the wrong approach

The quick fix you will see everywhere is one line in wp-config.php.

define( 'ALLOW_UNFILTERED_UPLOADS', true );

It gives administrators the unfiltered_upload capability, so both checks are skipped for them. They can then upload anything, including a .php file, into a folder the web server can reach. If an administrator account is ever phished or its password reused, an attacker uploads a web shell in seconds. A web shell is a PHP file that lets them run commands on your server from a browser. Keep this constant out of production sites. It is reasonable for a single one-off import, on a site where you are the only administrator. PHP should also be blocked in the uploads folder first, as our guide on blocking PHP execution in wp-content/uploads explains. Remove the line as soon as the import is done.

Some files do not belong in the Media Library at all. Theme fonts, JSON configuration and build files are part of the code, so ship them in the theme or a plugin and deploy them with it. Keep the Media Library for content that editors manage.

For the core details, the WordPress reference pages for wp_check_filetype_and_ext() and the upload_mimes filter show the current source.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.