skip to Main Content

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

3

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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…

    Login or Signup to reply.
  3. 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.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search