The uploaded file exceeds the upload_max_filesize directive in php.ini

KB ID 0001125 

Problem

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

file exceeds php upload

Solution

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

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

Execute the following command;

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

Try to upload your file again.

 

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

Submit a Comment

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