How to add files to WordPress larger than the allowed maximum size

Occasionally, I need to add files to one of my WordPress sites that are larger than the maximum upload size that is set on the server. I could, of course, go and raise this, but I don’t want to do that for the odd occasion it is needed.

Just uploading a file to the wp-content folder via sFTP isn’t enough as you also need to tell WordPress that the file is there. Enter WP-CLI.

Setting up WP-CLI

WP-CLI allows you to carry out WordPress admin instructions, but from the command line rather than the usual browser interface. We’re only going to look at attaching files to an existing WordPress install but the full list of commands are here or you can type wp help once WP-CLI has been installed.

Installing and running WP-CLI

Rather than rehash the installation instructions here you can read the comprehensive instructions on the WP-CLI website.

Once installed, you can check it out by typing wp cli. You may, if you are very unlucky, receive this dire warning if you have installed WP-CLI as root. In which case, you can either reverse the install and try again or add --allow-root to each and every command and suffer the consequences.

Updating WP-CLI

WP-CLI is self-updating, albeit with a little push in the right direction. Just enter wp cli update from the command line and if there is a new version you will be given the opportunity to update.

Using WP-CLI for Bulk Uploads

I should point out here that WP-CLI cannot actually do the upload itself; for that, you will need to use something such as sFTP/SCP to actually get the file onto your server, but once it is on there, you will need WP-CLI to make sure that WordPress knows about the file and you can use it.

WordPress places any files added via the media browser into the wp-content/uploads folder, creating a sub-folder for each year and month. I suggest that you try and add your files into the same structure to make them easier to find and to apply the same security as files uploaded by WordPress itself.

The wp-content/uploads/2009/03 and 04 folders

Registering Uploaded Files

To register your files and make WordPress aware of them you need to use the following WP-CLI command:

wp media import /path/to/your/uploads/filename.ext --title="Your File Title"

Using WP-CLI is much faster for bulk uploads compared to the WordPress admin interface, especially for large files.

The file will now appear in the WordPress media library just like any other file and you can use it in your posts.

Leave a Reply

Your email address will not be published. Required fields are marked *