如何更改 Wordpress 中的文件加载和传输容量

How to change file loading and transfer capacity in Wordpress

我将以下内容添加到我的 .htaccess 文件中,但仍然无法上传文件。

php_value upload_max_filesize 256M
php_value post_max_size 256M
php_value memory_limit 512M
php_value max_execution_time 600
php_value max_input_time 600

尝试将 set_time_limit 添加到 wp-config。php

set_time_limit( 600 );

将以下代码添加到您的 config.php 文件中。

@ini_set('upload_max_filesize' , '256M');
@ini_set('post_max_size', '256M');
@ini_set('memory_limit', '512M');
@ini_set('max_execution_time', '600');
@ini_set('max_input_time', '600');

使用代码或文本编辑器,将以下代码添加到现有或新的 php.ini 文件中:

upload_max_filesize = 32M
post_max_size = 64M
memory_limit = 128M

我认为这是您问题的正确答案 参考following URL:

创建或修改 .user.ini 文件

If your hosting provider has locked down the global PHP settings, they may have configured the server to work with .user.ini files instead of php.ini files.

upload_max_filesize = 32M
post_max_size = 64M
memory_limit = 128M

增加 Nginx 中的最大上传文件大小

在 Nginx 服务器上,您可以在 /etc/php/7.4/fpm/php.ini 找到 php.ini 文件。根据您安装的 PHP 版本,确切路径可能略有不同。

upload_max_filesize = 64M
post_max_size = 128M

使用 WordPress ‘upload_size_limit’ 过滤器

下面是 WordPress 贡献者 Drew Jaynes 提供的此过滤器的实际应用示例。它定义了所有 non-admin 角色的上传大小限制。

/**
* Filter the upload size limit for non-administrators.
*
* @param string $size Upload size limit (in bytes).
* @return int (maybe) Filtered size limit.
*/
function filter_site_upload_size_limit( $size ) {
// Set the upload size limit to 10 MB for users lacking the 'manage_options' capability.
if ( ! current_user_can( 'manage_options' ) ) {
// 10 MB.
$size = 1024 * 10000;
}
return $size;
}
add_filter( 'upload_size_limit', 'filter_site_upload_size_limit', 20 );

将以下代码添加到您的 config.php 文件中。

@ini_set('upload_max_filesize' , '256M');
@ini_set('post_max_size', '256M');
@ini_set('max_input_time', '600');