By default, WordPress and your hosting provider limit the file upload size because of technical reasons. Users who need to upload files that exceed the pre-set limit often get an error and the operation fails.
The two most common reason why this problem occurs is due to file size upload restrictions added to the following two areas:
- The upload_max_filesize directive in php.ini
- Fatal error: Allowed memory size of xxxxx bytes exhausted (tried to allocate xxxxx bytes) in /home/your-username/public_html/wp-includes/plugin.php on line xxxx
There are multiple ways of increasing WordPress max upload file size limit. In this article, I will discuss just the most popular ways that have worked for the majority of the WordPress websites. But before diving into the discussion, I will discuss three variables that play important role in this problem.
- Upload_max_filesize: This variable defines the maximum upload size of a single file.
- Post_max_size: This variable defines the maximum upload limit for a POST request. Note that a single request could include multiple files.
- Memory_limit: This variable defines the memory limit for a single script. This limit could be equal or more than upload_max_filesize.
Note: There is a relationship between upload_max_filesize and post_max_size. In many cases, post_max_size is set at a higher value than the upload_max_filesize. Here’s an example – if you have several files of 5MB, and the upload_max_filesize is set to 20MB, post_max_size cannot contain not more than 4 files.
Confirm the Default WordPress Max Upload File Size Limit
The default file upload size limit can be found by navigating to Media >> Add New.
As you could see from the following screenshot, the default maximum upload file size is set to 10MB.
In this tutorial, I will set the limit to 20MB. As discussed earlier, there are multiple ways of increasing the upload file size limit.
Check with the Hosting Provider
Hosting providers who specialize in WordPress hosting has a default option for increasing the file upload size limit (often located right on the dashboard).
For instance, If you are a Cloudways customer, login to their platform, navigate to Servers tab and then Settings & Packages. In the UPLOAD SIZE field, enter the file size you wish. Once done, don’t forget to click the Save Changes button at the bottom of the page.
Modify (or Create) php.ini
php.ini (located in the root directory of the hosting account) is a configuration file that customizes the behavior of PHP at runtime. It contains a list of settings including maximum upload file size, maximum execution time, upload directory, global variables, and display errors.
Due to security concerns, almost all hosting providers keep it hidden. To access the file, login to the hosting account, navigate to the root directory and search for php.ini. You might need to mark “Show Hidden Files”. If there is no such file, create a new one with the name: “php.ini”. Make sure that the file includes the above three mentioned variables
Since I need to set the maximum file upload size to 20MB, I will change the values of upload_max_filesize to 20MB and post_max_size to 25 MB so that a single 20MB file can be used in the body of the post. The good practice is to set post_max_size more than the upload_max_filesize.
upload_max_filesize = 20M
post_max_size = 25M
memory_limit = 30M
Note: “M” refers to “MB”, memory_limit should be equal or greater than the upload_max_filesize. To be on the safe side, I have set it to 30 MB.
Note that some hosting providers rename the file to php5.ini.
Modify (or Create) .htaccess File
.htaccess is short for Hypertext Access, a configuration file used by Apache servers. Typically, it is located in the root directory. If the file isn’t there, create it with the exact filename and extension “.htaccess”
I assume you already have the file, copy and paste the following lines of code just below where it says #End WordPress.
php_value upload_max_filesize 20MB
php_value post_max_size 25MB
php_value memory_limit 30MB
Note: While searching for .htaccess, don’t forget to mark “Show Hidden Files”. It might be hidden by your hosting provider.
Get Blazing Fast WordPress Hosting With
$25 FREE CREDIT
Modify WordPress Files
The above three methods are the most recommended ways of increasing the file upload size. However, for any reason, these methods don’t work, it is time to add to the WordPress files. Open up either wp-config.php or functions.php files, and paste the following lines of code:
@ini_set( ‘upload_max_size’ , ’20MB’ );
@ini_set( ‘post_max_size’, ’25MB’);
@ini_set( ‘memory_limit’, ’30MB’ );
Increase WordPress Max Upload File Size Through Plugin
The beauty of WordPress is that you will always find a plugin to solve the problem. If you do not want to do increase the file upload size manually, there is an excellent plugin named Increase Max Upload Filesize that will surely help you out. Just remember to enter the values in bytes (1024000 bytes = 1 MB). For 20 MB, multiply 1024000 with 20 and enter 20480000 in the textbox. Click Save Changes, and you are done!
The Problem Persists?
There is a slight possibility that none of the above methods work for your website. In such cases, Don’t Panic. Contact your hosting provider and they will help you out!
Upload Files Via FTP
FTP comes handy when you need to upload large files. Note that files uploaded via FTP to /wp-content/uploads/ directory aren’t displayed in the media library. There is an excellent plugin Media from FTP that registers these files in the library in just a few clicks.
If you think I have missed a popular method, feel free to mention it in the comments section below. If any of the mentioned methods worked for you, share the details in a comment.
The post How to Increase WordPress Max Upload File Size Limit appeared first on WPblog.