Resolving upload max file size php.ini Errors

Upload max file size php.ini error: If you encounter the error message The uploaded file exceeds the upload_max_filesize directive in php.ini while uploading files to your website, it means that the file size exceeds the limit set by the upload max file size directive in PHP configuration. Below are the steps to fix this issue using one of several different methods.

How to Fix the upload max file size php.ini Error

The uploaded file exceeds the upload_max_filesize directive in php.ini.

upload max file size php.ini

 

Adjust php.ini Settings (VPS/Dedicated Host)

If you have access to your server’s php.ini file, you can follow these steps:

  1. Locate your php.ini file. Common locations include:
    • /etc/php.ini (Linux)
    • C:\xampp\php\php.ini (XAMPP on Windows)
  2. Open the file and find the upload_max_filesize directive. Set it to a higher value, such as:
    upload_max_filesize = 20M
  3. Also, update post_max_size and memory_limit to accommodate larger uploads:
    post_max_size = 25M
    memory_limit = 128M
  4. Restart your web server for the changes to take effect.

Use the cPanel MultiPHP INI Editor (Shared Host)

If you are on shared hosting and don't have direct access to php.ini, you can update the max file size limits using the cPanel MultiPHP INI Editor:

  1. Log in to your hosting account's cPanel dashboard.
  2. Go to Software > MultiPHP INI Editor.
  3. Select your domain and update the upload_max_filesize, post_max_size, and memory_limit values.
  4. Save the changes, and they will apply to your PHP configuration.

Note: To make changes to the PHP configuration file via cPanel, try to use the MultiPHP INI Editor instead of manually editing the .htaccess file. This prevents potential conflicts.

Modify .htaccess to set upload max file size Limits

In some cases, you can edit your .htaccess file to set the upload max file size. To do this, add the following lines to the file:

php_value upload_max_filesize 20M
php_value post_max_size 25M
php_value memory_limit 128M

However, be cautious with this method as some servers do not allow php_value directives in .htaccess, and it may cause your site to break.

Modify the functions.php File in WordPress

Another method to set upload max file size limits is by modifying PHP settings via the functions.php file in your WordPress theme. This method may not work on all hosting environments, but it's worth a try:

  1. Open your WordPress admin dashboard and go to Appearance > Theme Editor.
  2. On the right-hand side, find and open the functions.php file for your active theme.
  3. Add the following code at the end of the file:
    
    @ini_set( 'upload_max_size' , '20M' );
    @ini_set( 'post_max_size', '25M' );
    @ini_set( 'memory_limit', '128M' );
        
  4. Click Update File to save your changes.

Note: This method may not work on all hosts, as some hosting providers block the ability to modify PHP values from within WordPress theme files. If it doesn’t work, revert to other methods like using php.ini or the cPanel MultiPHP INI Editor.

Troubleshooting: If your Site Breaks

If adding PHP directives to .htaccess causes your site to break, remove the lines you added, and use either the php.ini method or the cPanel MultiPHP INI Editor for making adjustments. Be sure to restart your web server or check with your hosting provider for further support.

Summary: To resolve upload max file size errors, you can modify your PHP settings through php.ini, the cPanel MultiPHP INI Editor, WordPress functions.php file, or by modifying the .htaccess file. Hopefully one of those methods provided helps you resolve your upload max filesize error, finally allowing you to upload larger files in WordPress.