Website Vidya
WordPressStep-by-Step Guide

How to fix “the uploaded file exceeds the upload_max_filesize directive in php.ini.” error

The error message "the uploaded file exceeds the upload_max_filesize directive in php.ini" means that the file you are trying to upload is larger than the maximum file size allowed by your server. To fix this error, you need to increase the...

RR
Website Vidya TeamLead Systems Educator
Published:
5 min read
How to fix “the uploaded file exceeds the upload_max_filesize directive in php.ini.” error
AI Executive SummaryCORE CIS AI

5 min read

The error message "the uploaded file exceeds the upload_max_filesize directive in php.ini" means that the file you are trying to upload is larger than the maximum file size allowed by your server. To fix this error, you need to increase the...

Key Highlights
  • Other Error Fixes
  • Prerequisites
  • 3 Simple Ways to Fix Uploaded File Exceeds upload_max_filesize error in WordPress
Grounded in full engineering runbookCORE CIS Ai Engine

The error message "the uploaded file exceeds the upload_max_filesize directive in php.ini" means that the file you are trying to upload is larger than the maximum file size allowed by your server. To fix this error, you need to increase the maximum file size allowed in your PHP configuration file.

In this article, we will learn how to fix this error by adjusting the upload_max_filesize variable in php.ini.

Other Error Fixes

Prerequisites

  • A working WordPress installation
  • Access to the server that hosts the WordPress installation
  • Access to a file manager (or cPanel)
  • A user account with sudo privileges
  • Access to a command line interface or terminal window

3 Simple Ways to Fix Uploaded File Exceeds upload_max_filesize error in WordPress

Method 1: Edit the .htaccess File

Using cPanel

Open the cPanel and launch the file manager.

Navigate to the root folder of your website and edit the .htaccess file.

Now, look for the php_value_upload_max_filesize and increase its value to 256. Which means you’re allowed to upload a file size of 256 MB.

php_value_upload_max_filesize 256M

The code snippet php_value_upload_max_filesize 256M is used to increase the maximum file upload size in a PHP environment.

Save the changes and exit the file.

Using Command Line Interface (CLI)

If you find yourself comfortable using a terminal then this method is for you.

We will perform the same thing that we did earlier. But here, we will be using a command line interface to quickly make the required changes.

This option is for those who use Cloud Servers like Linode or Digital Ocean and don’t have access to the cPanel.

Here are the steps:

Log in to your server using SSH and navigate to the WordPress website directory by running the following command:

cd /path/to/wordpress

Now, open and edit the .htaccess file using your favourite editor. In my case, I prefer using the vim editor.

To do that, run:

sudo vim .htaccess

Now, search for the php_value_upload_max_filesize and increase its value to 256.

Save the changes by pressing the ESC button on your keyboard, enter wq! and hit enter or return button.

Method 2: Editing the wp-config.php File

You can also increase the maximum file upload size by tweaking the wp-config.php file located in your root directory.

All you need to do is log in to the cPanel and access the public_html directory.

Here, search for the wp-config.php file and add the following line before the “That’s all, stop editing! Happy publishing” line:

@ini_set('upload_max_size' , '256M' );

The @ini_set() function tells PHP to set the specified value for the specified ini directive. In this case, we are setting the upload_max_filesize directive to 256 megabytes.

Once you have added this code snippet to the wp-config.php file, you need to save the file and then upload it to your web server. Once the file has been uploaded, you should be able to upload files that are up to 256 megabytes in size.

It is important to note that this method of increasing the maximum file upload size is not always reliable. Some web hosting providers may not allow you to change the values of the upload_max_filesize and post_max_size directives in the wp-config.php file.

If you are having problems increasing the maximum file upload size using this method, you may need to contact your web hosting provider for assistance.

Method 3. Updating php.ini to Fix the upload_max_filesize Error

The upload_max_filesize directive is defined in the php.ini file. This directive specifies the maximum size of a file that can be uploaded to a web server. If you are trying to upload a file that is larger than the upload_max_filesize directive, you will receive this error message.

The php.ini file is a configuration file that contains all of the PHP-related variables. These variables control how PHP behaves.

In general, if you’re using shared hosting, all limits are at the maximum value. If the problem still persists, contact your web hosting provider to suggest you a solution for any such errors.

If you’re managing a VPS or dedicated cloud server, this is the fix you will ever need.

The location of PHP may vary depending on the Linux distribution and PHP version you’re using.

If you’re on Ubuntu and using the latest version of PHP i.e., PHP 8, navigate to the /etc/php/8.1/apache2/ or /etc/php/8.1/fpm/ directory if you’re using FastCGI Process Manager.

Now, edit the php.ini file by running the following command:

sudo vim php.ini

Locate the upload_max_filesize directive and change its value to 256.

upload_max_filesize = 256M

Moreover, you would also want to adjust the following directives:

post_max_size = 256M
memory_limit = 512M
max_execution_time = 180

Conclusion

In this tutorial, you have learned three different ways to fix the uploaded file exceeds the upload_max_filesize directive in php.ini error in WordPress.

Here’s a quick recap:

  • Editing the .htaccess File Using cPanel and Command Line Interface (CLI).
  • Editing the wp-config.php file using @ini_set() function.
  • Updating php.ini to Fix the upload_max_filesize Error

Easy, right? If you have any questions or suggestions, don’t hesitate to comment down below!

Written by

Website Vidya Team

Technology educator and researcher at Website Vidya.

Discussion

0
Share your thoughts, ask a question, or suggest a tip...
Write →

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

WordPress•

How to Create a Table of Contents in WordPress

How to create a table of contents in WordPress? Did you ever want to add a table of contents just like Wikipedia has on its website? If yes, I’m going to show you a way that you use to put a similar table of contents box on your blog or web...

RR
Rajesh Rai
Read More
WordPress•

How to Upload SVG to WordPress - 3 Easy Methods

Do you want to embed SVG in the WordPress website? Learn how to upload SVG to WordPress effortlessly with 3 simple methods. Enhance your website with captivating graphics. This how-to guide is for all levels. By default, the WordPress conte...

RR
Rajesh Rai
Read More
WordPress•

How to Hide or Remove the WordPress Admin Toolbar

WordPress displays a toolbar at the top of every page by default. Whether you are viewing your website’s admin dashboard or any page, you will find this WordPress toolbar on every page and it is very annoying for most of the people. Moreove...

RR
Rajesh Rai
Read More