简体   繁体   English

增加 WordPress 中的上传大小

[英]Increasing the upload size in WordPress

I wanted to increase the file upload size limit in wordpress without editing php.ini So I tried adding .htaccess to the wp-content/uploads directory with rules like these:我想在不编辑 php.ini 的情况下增加 wordpress 中的文件上传大小限制所以我尝试使用如下规则将 .htaccess 添加到 wp-content/uploads 目录:

php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M

This doesn't work in wp-content/uploads, the upload max is still 2MB This does work if I put this in the websites .htaccess file though.这在 wp-content/uploads 中不起作用,上传最大仍然是 2MB 这确实有效,如果我把它放在网站 .htaccess 文件中。

Why won't this work if I just put the htaccess in the uploads directory?如果我只是将 htaccess 放在上传目录中,为什么这不起作用? Are there any risks in increasing the upload size for the entire site?增加整个网站的上传大小是否有任何风险?

.htaccess won't work unless the PHP script handling the upload exists at wp-content/uploads/ (which it does not). 除非处理上传的PHP脚本存在于wp-content/uploads/ (否则, .htaccess将不起作用)。 Placing it in that folder does not have the result you may expect because it only impacts scripts located in that folder. 将其放在该文件夹中并不会产生预期的结果,因为它只会影响该文件夹中的脚本。

You might try placing .htaccess file into /wp-admin/ which will change upload settings for all files handled inside the admin PHP scripts. 您可以尝试将.htaccess文件放入/wp-admin/ ,这将更改在管理PHP脚本中处理的所有文件的上载设置。

Unclear from your post where else users may be uploading files... are you using upload forms in your public-facing website? 从您的帖子中不清楚用户可能还在其他地方上传文件...您是否在面向公众的网站中使用上传表单? If so, you may not want to update the settings server-wide. 如果是这样,您可能不想在服务器范围内更新设置。 If not, I see no big risks in making the change. 如果没有,我认为进行更改没有太大的风险。

For increase PHP's file upload limit. 为了增加PHP的文件上传限制。

In php.ini file, change the parameter to whatever size you need (example: ) 在php.ini文件中,将参数更改为所需的大小(例如:)

upload_max_filesize = 32M 

... Simply create blank text file. ...只需创建空白文本文件。 Save As php.ini 另存为php.ini

Inside the text file copy-paste the following: 在文本文件内复制粘贴以下内容:

upload_max_filesize = 32M
post_max_size = 32M

============================ ============================

Unable to access root directory , than add this to top of wp-config.php define('WP_MEMORY_LIMIT', '64M'); 无法访问根目录,然后将其添加到wp-config.php define('WP_MEMORY_LIMIT','64M');

To Increase the Maximum file size upload in wordpress 要增加在Wordpress中上传的最大文件大小

find the php.ini location 找到php.ini位置

#find / -iname php.ini

Get into the folder By default it is 2M we can incerase by setting value to the parameter 进入文件夹默认情况下为2M,我们可以通过将值设置为参数来确定

#vim php.ini
 upload_max_filesize = <Userdefined size>   (For eg 20M)
 post_max_size = <Userdefined size >

Then if you are using php7.0 restart php7.0-fpm service 然后,如果您使用的是php7.0,请重新启动php7.0-fpm服务

#systemctl reload php7.0-fpm.service

如果.htaccess不变,php.ini不变,则在根文件夹服务器中搜索.user.ini文件,并搜索upload_max_filesize和post_max_size值并替换它们。

For increasing PHP's file upload limit. 用于增加PHP的文件上传限制。

Go to wordpress root directory and open .htaccess file. 转到wordpress根目录并打开.htaccess文件。 In my case it was found in /var/www/html 就我而言,它位于/ var / www / html

php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300

The above code increased my file upload limit to 128 MB in wordpress 上面的代码在wordpress中将文件上传限制增加到128 MB

2021: 2021 年:

  1. Access /etc/php/8.0/apache2/php.ini访问/etc/php/8.0/apache2/php.ini
  2. Increase the value of post_max_size .增加post_max_size的值。 The default value is 8M .默认值为8M
  3. Restart the server with sudo service apache2 restartsudo service apache2 restart服务器

Try to add this to functions.php of your theme 尝试将其添加到主题的functions.php

@ini_set( 'upload_max_size' , '10M' );
@ini_set( 'post_max_size', '20M');
@ini_set( 'memory_limit', '32M' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM