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 not, 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. That would be a bit indiscriminate of them, right?

The default list of WP mime types 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',
	'js'                           => 'application/javascript',
	'pdf'                          => 'application/pdf',
	'swf'                          => 'application/x-shockwave-flash',
	'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 nice, but the current reality might be different. 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' );

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.

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

To fix this, you’ll need to instruct WP to support EPUB using a little bit of code. 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! 🙂