How to Enable EPUB Uploads for WP and WooCommerce

If you are trying to upload EPUB to WordPress or sell EPUB files or other ebooks using WooCommerce, you might have come across one obscure little problem: WP doesn’t support EPUB by default. ๐Ÿ˜ณ

You might be having trouble uploading EPUB files to your WP Media Library with a “This file cannot be processed by the web server” error message, and/or you might run into the “Invalid download link” error screen when you try to download your WooCommerce EPUB. These error messages simply mean that WordPress does not enable this file/media type (MIME type) by default, or the file type has been turned off by a security plugin (or your hosting provider). Keep reading to learn how to fix that.

If you are using WooCommerce and look closely at your WooCommerce product file list, you might see the very subtle red asterixes next to disabled file types. If the EPUB MIME type isn’t active, then all your EPUB files will be disabled automatically. Otherwise, if you are not using WooCommerce, there really are no clues other than the error messages mentioned above. This can be maddening!

But don’t worry, there’s a quick fix. If you’re using PDF Ink, just check the box in the Integration Settings that says “Facilitate WP EPUB uploads.” You’re done.

If you are not using PDF Ink, read below for the quick fix.

This file cannot be processed by the web server

By default, WordPress does not allow you to upload JUST ANY type of file. Think about it: that would be a bit indiscriminate of them, right? WordPress tries to be a secure, reliable platform, so they have to draw lines somewhere.

The default list of file mime types allowed by WordPress looks like this:

<?php
array(
	// Image formats.
	'jpg|jpeg|jpe'                 => 'image/jpeg',
	'gif'                          => 'image/gif',
	'png'                          => 'image/png',
	'bmp'                          => 'image/bmp',
	'tiff|tif'                     => 'image/tiff',
	'webp'                         => 'image/webp',
	'avif'                         => 'image/avif',
	'ico'                          => 'image/x-icon',

	'heic'                         => 'image/heic',
	'heif'                         => 'image/heif',
	'heics'                        => 'image/heic-sequence',
	'heifs'                        => 'image/heif-sequence',

	// Video formats.
	'asf|asx'                      => 'video/x-ms-asf',
	'wmv'                          => 'video/x-ms-wmv',
	'wmx'                          => 'video/x-ms-wmx',
	'wm'                           => 'video/x-ms-wm',
	'avi'                          => 'video/avi',
	'divx'                         => 'video/divx',
	'flv'                          => 'video/x-flv',
	'mov|qt'                       => 'video/quicktime',
	'mpeg|mpg|mpe'                 => 'video/mpeg',
	'mp4|m4v'                      => 'video/mp4',
	'ogv'                          => 'video/ogg',
	'webm'                         => 'video/webm',
	'mkv'                          => 'video/x-matroska',
	'3gp|3gpp'                     => 'video/3gpp',  // Can also be audio.
	'3g2|3gp2'                     => 'video/3gpp2', // Can also be audio.
	// Text formats.
	'txt|asc|c|cc|h|srt'           => 'text/plain',
	'csv'                          => 'text/csv',
	'tsv'                          => 'text/tab-separated-values',
	'ics'                          => 'text/calendar',
	'rtx'                          => 'text/richtext',
	'css'                          => 'text/css',
	'htm|html'                     => 'text/html',
	'vtt'                          => 'text/vtt',
	'dfxp'                         => 'application/ttaf+xml',
	// Audio formats.
	'mp3|m4a|m4b'                  => 'audio/mpeg',
	'aac'                          => 'audio/aac',
	'ra|ram'                       => 'audio/x-realaudio',
	'wav|x-wav'                    => 'audio/wav',
	'ogg|oga'                      => 'audio/ogg',
	'flac'                         => 'audio/flac',
	'mid|midi'                     => 'audio/midi',
	'wma'                          => 'audio/x-ms-wma',
	'wax'                          => 'audio/x-ms-wax',
	'mka'                          => 'audio/x-matroska',
	// Misc application formats.
	'rtf'                          => 'application/rtf',
	'pdf'                          => 'application/pdf',
	'class'                        => 'application/java',
	'tar'                          => 'application/x-tar',
	'zip'                          => 'application/zip',
	'gz|gzip'                      => 'application/x-gzip',
	'rar'                          => 'application/rar',
	'7z'                           => 'application/x-7z-compressed',
	'exe'                          => 'application/x-msdownload',
	'psd'                          => 'application/octet-stream',
	'xcf'                          => 'application/octet-stream',
	// MS Office formats.
	'doc'                          => 'application/msword',
	'pot|pps|ppt'                  => 'application/vnd.ms-powerpoint',
	'wri'                          => 'application/vnd.ms-write',
	'xla|xls|xlt|xlw'              => 'application/vnd.ms-excel',
	'mdb'                          => 'application/vnd.ms-access',
	'mpp'                          => 'application/vnd.ms-project',
	'docx'                         => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
	'docm'                         => 'application/vnd.ms-word.document.macroEnabled.12',
	'dotx'                         => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
	'dotm'                         => 'application/vnd.ms-word.template.macroEnabled.12',
	'xlsx'                         => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
	'xlsm'                         => 'application/vnd.ms-excel.sheet.macroEnabled.12',
	'xlsb'                         => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
	'xltx'                         => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
	'xltm'                         => 'application/vnd.ms-excel.template.macroEnabled.12',
	'xlam'                         => 'application/vnd.ms-excel.addin.macroEnabled.12',
	'pptx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
	'pptm'                         => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
	'ppsx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
	'ppsm'                         => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
	'potx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.template',
	'potm'                         => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
	'ppam'                         => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
	'sldx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
	'sldm'                         => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
	'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote',
	'oxps'                         => 'application/oxps',
	'xps'                          => 'application/vnd.ms-xpsdocument',
	// OpenOffice formats.
	'odt'                          => 'application/vnd.oasis.opendocument.text',
	'odp'                          => 'application/vnd.oasis.opendocument.presentation',
	'ods'                          => 'application/vnd.oasis.opendocument.spreadsheet',
	'odg'                          => 'application/vnd.oasis.opendocument.graphics',
	'odc'                          => 'application/vnd.oasis.opendocument.chart',
	'odb'                          => 'application/vnd.oasis.opendocument.database',
	'odf'                          => 'application/vnd.oasis.opendocument.formula',
	// WordPerfect formats.
	'wp|wpd'                       => 'application/wordperfect',
	// iWork formats.
	'key'                          => 'application/vnd.apple.keynote',
	'numbers'                      => 'application/vnd.apple.numbers',
	'pages'                        => 'application/vnd.apple.pages',
)
	);

That’s a nice long list, but it doesn’t include EPUB, and the current active list might be different than what WordPress sets. There are several file types that are immediately nullified by WP itself even though they are on this masterlist: .htm, .html, .js, and .exe. A plugin or maybe even your host might have removed some other types from this list. The following PHP will output an array (list) of your current allowed WP mime types to the screen:

<?php
$mime_types = wp_get_mime_types();
echo "<pre>";
print_r( $mime_types );
echo "</pre>";

It will show the mime types allowed on YOUR installation. If your file format isn’t on this list, of course you’re going to get a “This file cannot be processed by the web server” error. It’s possible that your hosting, or a plugin or even a theme has removed the mime type, possibly for security reasons. You can try adding it back in using code similar to that below. For example if you’re just trying to add in the SVG MIME type (not necessarily wise, but you do you), add this code using Code Snippets or via your child theme functions.php file:

/**
 * Add the 'SVG' MIME type to the existing WP MIME list
 * @param array $mimes
 * @return array
 */
function add_svg_mime_to_wp( $mimes ) {
  $mimes['svg'] = 'image/svg+xml';
  return $mimes;
}
add_filter( 'upload_mimes', 'add_svg_mime_to_wp' );

Here’s another example, this time for JavaScript and EXE. Don’t do this.

/**
 * Add the 'JS' and EXE MIME type to the existing WP MIME list
 * @param array $mimes
 * @return array
 */
function add_two_mimes_to_wp( $mimes ) {
  $mimes['js'] = 'application/javascript';
  $mimes['exe'] = 'application/x-msdownload'; 
  return $mimes;
}
add_filter( 'upload_mimes', 'add_two_mimes_to_wp' );

Hopefully our use of repetition in the examples has helped you to see how to apply this to any file type, or more than one file type at the same time.

We recommend removing this code or commenting it out when you are finished with your uploads. To comment it out (and disable while leaving code in place), add // in front of add_filter:

/**
 * Add the 'SWF' MIME type to the existing WP MIME list
 * @param array $mimes
 * @return array
 */
function add_swf_mime_to_wp_disabled( $mimes ) {
  $mimes['swf'] = 'application/x-shockwave-flash'; // IYKYK
  return $mimes;
}
// add_filter( 'upload_mimes', 'add_swf_mime_to_wp_disabled' );

The Quickest Fix

Sometimes it’s nice to achieve something with only 5 lines of code like you could do with the code above. But the rest of us will more likely use a WP plugin to audit and add MIME (media) types. We recommend deactivating the plugin when you are finished with your uploads.

If you’re not using PDF Ink but need EPUB…

The Constant Down and Dirty Way:

Kinsta posted a very similar blog post to this one, recommending use of the ALLOW_UNFILTERED_UPLOADS constant as the We will show you how to do that, but don’t recommend it (and are surprised a reputable hosting company would recommend it). All you have to do is open the wp-config.php file in the root of your WP installation, and add the following line on a new line below the $table_prefix = line.

define('ALLOW_UNFILTERED_UPLOADS', true);

You could do this, but it’s much safer to allow only the file types you’re using, not any file type. Again, there are security reasons why WP does not allow the upload of just ANY file type. Namely, some file types can behave like Trojan Horses.

If you *DO* use this one line of code to get your wingnut file type uploaded, DO remove the line of code after your file is successfully uploaded.

The Cherry-Picked (Safer) Way:

You’ll need to instruct WP to support EPUB (or the MIME type you need) using a little bit of code added to your WordPress installation.

Here is the PHP snippet to add the EPUB MIME type:

<?php
/**
 * Add the 'epub' MIME type to the existing WP MIME list
 * @param array $mimes
 * @return array
 */
function add_epub_mime_to_wp( $mimes ) {
  $mimes['epub'] = 'application/epub+zip';
  // other mime types, like mobi/prc, could be added below, like so:
  // $mimes['mobi'] = 'application/x-mobipocket-ebook';
  // $mimes['prc'] = 'application/x-mobipocket-ebook';

  return $mimes;
}
add_filter( 'upload_mimes', 'add_epub_mime_to_wp' );

This code can be added to the bottom of your WP (child) theme functions.php file using FTP/SSH, or your File Manager of choice. Alternatively you can use the WordPress plugin called Code Snippets to add the code to your WP installation so that WP parses it on every page load. Or if you want to skip adding what could be just 5 lines of code to your site, you can add hundreds instead by installing yet another plugin that will do something for you once you master its settings. ๐Ÿ˜‰

If you’ve added this code to your WP site, and uploads still aren’t working, you might try adding these lines to your .htaccess file (if you’ve got an Apache server). You can also view active MIME types in the “MIME Types” section of your cPanel (under “Advanced”).

AddType application/epub+zip .epub
AddType application/x-mobipocket-ebook .mobi
AddType application/x-mobipocket-ebook .prc

If you’re not on an Apache server or this goes over your head, reach out to your hosting provider support channel for help.

A human wrote this blog post. Thanks for reading! ๐Ÿ™‚