How to Increase the Maximum Upload Size in WordPress

The maximum upload size is determined by server settings and a WordPress filter.

Problem

You try to upload a file but WordPress complains that the file size exceeds the maximum upload size.

Message displayed by WordPress when you try to upload an attachment whose size is greater than the maximum allowed size.

Background

This problem occurs because the size of the file is greater than some limits configured in the server. The solution is to adjust the settings involved in the file upload process.

  • upload_max_filesize —defines the maximum allowed size for file uploads.
  • post_max_size —defines the maximum allowed size for POST requests. This setting also affects file uploads and should be greater than upload_max_filesize.
  • memory_limit —defines the maximum amount of memory that a script can allocate. This setting should be greater than post_max_size.

Hosting restrictions

If you are using a hosting provider, the best solution is to call customer support. Most hosts set the settings above to a read-only value, so other solutions will fail. This is especially true in the case of shared hosting.

Solution 1

The file php.ini contains the PHP configuration of the server. In most cases, it is located in the root directory of the server, but this can vary from host to host.

Step 1: Add the code below to the file php.ini and replace values with the actual ones. Make sure each setting appears only once in php.ini.

Step 2: Save the file. Try to upload a file of the desired size.

; Allow a maximum of 150 megabytes in file uploads 
upload_max_filesize=150M

; Allow a maximum of 400 megabytes in POST requests
post_max_size=400M

; Limit memory allocation to 500 megabytes
memory_limit=500M

Solution 2

WordPress creates the file .htaccess in the root directory of the installation to indicate how the server should process each request.

Step 1: Add the code below to the file .htaccess and replace values with the actual ones.

Step 2: Save the file. Try to upload a file of the desired size. If an internal server error occurs, remove the code. It means that the server does not allow php_value directives.

# Allow a maximum of 150 megabytes in file uploads 
php_value upload_max_filesize 150M

# Allow a maximum of 400 megabytes in POST requests
php_value post_max_size 400M

# Limit memory allocation to 500 megabytes
php_value memory_limit 500M

Solution 3

Another solution is to try to change the server configuration from WordPress.

Step 1: Add the code below to WordPress and replace values with the actual ones.

Step 2: Try to upload a file of the desired size.

// Allow a maximum of 150 megabytes in file uploads 
@ini_set('upload_max_filesize', '150M');

// Allow a maximum of 400 megabytes in POST requests
@ini_set('post_max_size', '400M');

// Limit memory allocation to 500 megabytes
@ini_set('memory_limit', '500M');

Solution 4

In some cases, upload_max_filesize, post_max_size, and memory_limit are high enough, but the upload size is limited by the 'upload_size_limit' filter.

Apply this procedure to adjust the value returned by this filter.

Further reading

I recommend the other tutorials in this series to learn more about managing attachments in WordPress.

Source code

The source code developed in this tutorial is available here.