Question: PHP The uploaded file exceeds the upload_max_filesize directive in php.ini

Question

PHP The uploaded file exceeds the upload_max_filesize directive in php.ini

Answers 4
Added at 2017-01-04 13:01
Tags
Question

Before you mark this as duplicate, hear me out. I've tried all the suggestions I can find online. None works. I've restarted countless times. Detailed list of what I've tried below.

Here's my setup:

  • Nginx 1.10
  • PHP 7.0
  • WordPress 4.7
  • I'm on a VPS. I have access and control over EVERY single file!

Here's what I want to do:

  • Increase the upload file size for my WordPress.

Why?

  • Anytime I upload a file size bigger than 2 megabytes, I get this error: The uploaded file exceeds the upload_max_filesize directive in php.ini. That's all it tells me.

Here's what I have done:

  1. a. So out of common sense, I go into /etc/php/7.0/cli/php.ini because php.ini -i tells me the loaded configuration is from that file. In the php.ini file, I change the upload_max_filesize = 2M to upload_max_filesize = 10M

    b. I go ahead to restart, both Nginx (sudo service nginx restart), and PHP (sudo service php7.0-fpm restart)

Above Doesn't work as 2 other approaches below: I still get:

The uploaded file exceeds the upload_max_filesize directive in php.ini.

  1. I create my own user.ini under /etc/php/7.0/cli/conf.d/ folder with contents, upload_max_filesize = 10M

I go ahead to do 1. b. Still same error

  1. They say something is called error_reporting. I go ahead to locate the error reporting in my php.ini file. I change from the first line below to the second: ;error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_reporting = E_ALL

I do 1. b., Still doesn't work.

So what the #&)#(* is wrong with my setup and what again do I have to change somewhere else?

Is it even changeable? I've read and tried almost every single suggestion online, and it never works.

It has never been an issue for me, the 2 max upload, but I'm importing a wordpress xml file, which is just 3 Mb, and I've spent a couple of hours already trying to get this thing to work.

By default, can't the upload size be a bit higher. 2 Megabyte is even ridiculous for a site in recent years. At least 5 is much better.

Any help is appreciated!

Answers
nr: #1 dodano: 2017-01-04 13:01

Case 1 : Add php.ini in wp-admin folder

Navigate to wp-admin folder. Scroll down to see if you have a php.ini file in there.If you didn’t add one at some point.

upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

Case 2 : Add code to .htaccess

Open or create the .htaccess file in the root folder and add the following code:

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
nr: #2 dodano: 2017-01-04 13:01

You're looking at the php.ini file for the CLI, you need to look at the PHP ini file for the web server you're running. Within the WP directory, create a temporary php file, and have it contain <?php phpinfo(); navigate to that file in the browser and find the php.ini file you actually need to change, then make the change as required.

NOTE: Remove this file once you're done with your checks, having this information visible to the public is a security risk

nr: #3 dodano: 2017-01-04 13:01

Add below code into theme's function.php file

@ini_set( 'upload_max_size' , '64M' );
@ini_set( 'post_max_size', '64M');
@ini_set( 'max_execution_time', '300' );

OR

Create php.ini into root folder with below lines:

upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

Add code into .htaccess file:

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
nr: #4 dodano: 2017-01-04 13:01

What does php -i | grep 'upload_max_filesize' give you? The 10M you set or a different value. If it's giving you the latter then you're editing the wrong php.ini file. You can use php --ini to figure which config file is loaded

Source Show
◀ Wstecz