Abeer Sul
Abeer Sul

Reputation: 984

Why is PHP not allowing me to upload more than 2MB file?

I can't upload an image more than 2MB in my website form.

I have set up the needed settings in /etc/php/7.4/fpm/php.ini:

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 100M  

.
.

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = ON
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

.
.

; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit = 128M 

But the problem is that when I print php info in my index page I get different output :/

enter image description here

enter image description here

enter image description here

Why is this happening and how can I fix it?

NOTE: I'm serving my website with nginx if it matters (see nginx settings) enter image description here

Upvotes: 1

Views: 2366

Answers (3)

Tushar
Tushar

Reputation: 1

If Upper answers not fixed then try below steps:

  1. create user.ini file into additional ini file loaded location - see phpInfo() to find the location path. (search keyword- Additional .ini files)
  2. Insert the lines what we need to modify. Ex: max_upload_size = 20M
  3. Save and restart apache or respective server.

Upvotes: 0

Abeer Sul
Abeer Sul

Reputation: 984

Finally issue fixed:

the solution was to add php.ini and .user.ini files in the project's public directory to set the needed values (both files):

upload_max_filesize = 20M
post_max_size = 20M

like this:

enter image description here

I didn't find the real reason why updating /etc/php/7.4/fpm/php.ini but these 2 files finally fixed it

Upvotes: 1

Kinglish
Kinglish

Reputation: 23654

Two PHP configuration options control the maximum upload size: upload_max_filesize and post_max_size. If you're going to increase those significantly, consider upping the max_input_time and max_execution_time values as well

If you can't find the source of the 2mb setting in php.ini you can override in a .htaccess file

php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_input_time 300
php_value max_execution_time 300

Or directly in your PHP pages if need be

<?php 
 ini_set('upload_max_filesize', '10M');
 ini_set('post_max_size', '10M');
 ini_set('max_input_time', 300);
 ini_set('max_execution_time', 300);
?>

for example...

Upvotes: 1

Related Questions