The uploaded file exceeds the upload_max_filesize directive in php.ini

upload_max_filesize KB ID 0001125 

Problem

When attempting to upload a file to your website, (in my case from within WordPress). You see this error.

upload_max_filesize file exceeds php upload

Solution: upload_max_filesize

Update: 27-05-25: This started plaguing me again recently, and despite me searching all over for php.ini files I could NOT fix it, turns out there was a typo in the php.ini file that was stopping the whole file from loading properly. I uploaded the php.ini file to ChatGPT and asked it to analyse it, (that’s how I found out!)

If you are on ‘shared hosting‘ then you may not have access to your php.ini file, if that is the case you should add the following to your .htaccess file, (this will be a hidden file in the root folder of your website).

#########
php_value upload_max_filesize 50M
php_value post_max_size 50M
php_value max_execution_time 500
php_value max_input_time 500
#########

If , (like me), you have your own server, then you will need to edit the php.ini file directly, but where is it? Executing a ‘whereis php.ini‘ command  in my case showed me a few copies in various locations, but which one was live?

I’m assuming your website is installed in /var/www/html, so change the commands if yours is in a different location. I’m going to create a .php file in the root of my website, then browse to this file, it will show me all my .php settings and tell me where the live copy of php.ini is located.

I use nano, if you don’t have it installed, enter the hell that is the ‘vi editor’ and use that instead 🙂

nano /var/www/html/info.php

Then paste in the following text;

<?php phpinfo(); ?>

Then browse to the info.php file on your website with a web browser, i.e. http://www.your-website.com/info.php. You should see something like this.

 

info.php code upload_max_filesize

php ini file location

You can see that the ‘Loaded Configuration File’ is in /etc/php.ini

WARNING: Now it’s a little bit of a security hole having this sat there, so let’s delete this file on the server with the following command.

rm /var/www/html/info.php
THEN Enter 'y' to confirm.

How To Edit The php.ini File : upload_max_filesize

Execute the following command, (change the path as appropriate.)

nano /etc/php.ini

edit php.ini

Locate Upload_max_filesize and change its setting accordingly, by default it’s only 2MB.

00004

Also change your post size setting, as the default is only 8MB.

max post size

Save and exit the file, then restart Apache.

/sbin/service httpd restart

Or, if using NGINX.

sudo systemctl reload nginx

Then try to upload your file again.

Related Articles, References, Credits, or External Links

Description of core php.ini directives

Author: PeteLong

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *