we have a multisite installation with following configuration:

bash-5.0# cat /usr/local/etc/php/conf.d/uploads.ini
file_uploads = On
memory_limit = 500M
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 600
max_file_uploads = 50000
max_execution_time = 5000
max_input_time = 5000

Our /usr/local/etc/php/php.ini has:

;;;;;;;;;;;;;;;;
; 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 = 2M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

but on the wp-admin panel we see this:

enter image description here

How an we fix this? None of the existing answers helped here. we checked functions.php file. It does not have any ini_set calls in it.

Running phpinfo we have observed:

Loaded Configuration File => /usr/local/etc/php/php.ini
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini,
...
/usr/local/etc/php/conf.d/uploads.ini

post_max_size => 100M => 100M
upload_max_filesize => 100M => 100M

https://developer.wordpress.org/reference/functions/wp_max_upload_size/

in

function wp_max_upload_size() {
    $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
    $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
 
    /**
     * Filters the maximum upload size allowed in php.ini.
     *
     * @since 2.5.0
     *
     * @param int $size    Max upload size limit in bytes.
     * @param int $u_bytes Maximum upload filesize in bytes.
     * @param int $p_bytes Maximum size of POST data in bytes.
     */
    return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
}
有帮助吗?

解决方案

Upon debugging we found the wp_max_upload_size function was returning 1MB. The u_bytes and p_bytes were as expected and equal to 100MB as defined in our uploads.ini file but the application of upload_size_limit filter changed the size to 1MB i.e., the problem was at:

return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );

A upload_size_limit_filter is defined in wp-includes/ms-functions.php and is wired up to execute only for a multisite installation. (the wiring code is in wp-includes/ms-default-filters.php. The filename has a ms prefix standing for multisite):

// this function runs only for a multisite installation of wordpress
function upload_size_limit_filter( $size ) {
        $fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 );
        if ( get_site_option( 'upload_space_check_disabled' ) ) {
                return min( $size, $fileupload_maxk );
        }
 
        return min( $size, $fileupload_maxk, get_upload_space_available() );
}

and tracing the code path we found that fileupload_maxk equalled 1536000 and so this is what was causing the issue. The fileupload_maxk value is fetched from MySQL.

Continuing, we could see this in MySQL DB. The wp_sitemeta table only exists for a multisite installation:

mysql> select * from wp_sitemeta where meta_key = 'fileupload_maxk';
+---------+---------+-----------------+------------+
| meta_id | site_id | meta_key        | meta_value |
+---------+---------+-----------------+------------+
|       7 |       1 | fileupload_maxk | 1500       |
+---------+---------+-----------------+------------+
1 row in set (0.00 sec)

and so the fix for this problem is to update this value. It can be done using wp-cli as follows. We are using a multisite installation so have to use wp site command:

bash-5.0# wp site option update fileupload_maxk 10000 --allow-root
Success: Updated 'fileupload_maxk' site option.

This updates the entry in MySQL and the issue is fixed. In short, it seems that the fileupload_maxk does not seem to be well known. None of our Google searches on original query led us to it. Here is another answer on SO that talks about fileupload_maxk.

许可以下: CC-BY-SA归因
scroll top