Why it occurs?

Most of the hosting providers (like Apache) set limits to the PHP memory designated for running applications and scripts. When u try to upload some contents through WordPress Management Interface, then the problem occurs : The uploaded file exceeds the upload_max_filesize directive in php.ini which is an error that occurs on your WordPress site when you upload a file that exceeds the limitations set by your webserver. This article provides some methods that would fix the error by increasing the default limit of upload_max_filesize

How to Fix the upload_max_filesize Error?

Method 1. Updating the .htaccess File

If your web server is using Apache and PHP is set as an Apache module (like me), then you can add a few lines of code in your WordPress .htaccess file to increase the max upload size in WordPress.
To access your .htaccess file, connect to your server via SSH and navigate to the folder where WordPress is installed. Open up .htaccess file in a code editor such as Vim and add the following lines:

php_value upload_max_filesize 64M
php_value post_max_size 128M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300


This defines the max upload size in Megabytes. Replace the numbers as your requirement. The max execution time and max input time are in seconds. The execution time defines the limit of time spent on a single script.

Method 2. Editing the wp-config.php File

Another way of changing the upload size in WordPress is to define the size parameter in the wp-config.php file. To do that, access your WordPress root directory using SSH Root and locate a wp-config.php file. Then open it with Vim and add the following lines before before That’s all, stop editing! Happy publishing”line:

@ini_set( 'upload_max_size' , '20M' );
@ini_set( 'post_max_size', '13M');
@ini_set( 'memory_limit', '15M' );


Last ultmate method: Updating php.ini

Since many people could not find where is php.ini, here I propse a naive way: to use the phpinfo() function. It will tell you where php.ini is located, and it will also output all the important PHP configuration information.
You can run phpinfo() by creating a .php file using Vim or whatever and calling that function. Go ahead and create the phpinfo.php file in the root folder of your WordPress with the following contents:

<?php
phpinfo();
?>


Save it and run the https://your-wordpress-site.com/phpinfo.php URL in your browser, and you should see the output of phpinfo(). Look for the following section.

As you see, there are two sections. The first one, Configuration File (php.ini) Path, indicates the default path of the php.ini file in your system. And the second one, Loaded Configuration File, is the path from where the php.ini file is being loaded when PHP is run.
Now you can edit the php.ini file indicated in the Loaded Configuration File section. Add the following lines to this file or change the correspoding parameters in the file:

upload_max_filesize = 256M
post_max_size = 256M
memory_limit = 512M
max_execution_time = 180