Set maximum file upload size for media attachments using htaccess

There are quite a few different methods to set a maximum file upload size for media attachments. The maximum attachments limit can be set either through apache using the .htaccess file or via the wp-config.php file which resides in the root of your server. Make sure though to use only one method at the same time.

In this post, We will show you how to define a maximum size limit for your WordPress media files using .htaccess. First, copy the snippet bellow and paste it at the bottom of your .htaccess file. Then, update the parameters of attachments Size and  Timeout according to your preferences.

As you can see, We are setting here the maximum attachment size to 4MB and the timeout to 120 (2 minutes).

.htaccess
# Set maximum upload size for attachments via htaccess
php_value upload_max_filesize 4M
php_value post_max_size 4M
php_value max_execution_time 120
php_value max_input_time 120

If you couldn’t set up the maximum size limit through the .htaccess file successfully, try using the wp-config.php method.