[WordPress] How to fix ‘the uploaded file exceeds the upload_max_filesize directive in php.ini’ error
by Riley MacDonald, September 20, 2017

I’ve run into this error several times while developing themes for WordPress. While many blogs have lists of suggested fixes for this issue I think it’s worthwhile covering how I would approach solving this error as opposed to offering random solutions.

Problem:
This error is thrown when the defined upload_max_filesize variable is smaller than the file you’re trying to upload. While this variable is defined in php.ini it can be a bit confusing exactly which php.ini you should be modifying (wordpress, apache, etc).

Approach
Let’s identify which php.ini is being referenced. Add the following echo snippet somewhere you can view it’s output (on one of the pages on your site).

1
2
3
4
<?php 
    echo ini_get('upload_max_filesize');
    echo phpinfo(); 
?>

This prints the current value of the upload_max_filesize variable which needs to be increased. At this time you can verify your filesize is greater than the configured value. Following output contains all the information for your PHP configuration. Observe the following:

  • Loaded Configuration File: /etc/php5/apache2/php.ini
  • upload_max_filesize: 2M

This data verifies the path of the php.ini file which requires modifications and verifies the current value of upload_max_filesize. Pop open your favorite text editor and update the value of php.ini to resolve the issue. Note: You may need to restart the machine or apache2 for these changes to take effect.

Open the comment form

Leave a comment:

Comments will be reviewed before they are posted.

User Comments:

Be the first to leave a comment on this post!