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_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.
Why won't this work if I just put the htaccess in the uploads directory? 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). 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.
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.
In php.ini file, change the parameter to whatever size you need (example: )
upload_max_filesize = 32M
... Simply create blank text file. Save As 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');
To Increase the Maximum file size upload in wordpress
find the php.ini location
#find / -iname php.ini
Get into the folder By default it is 2M we can incerase by setting value to the parameter
#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
#systemctl reload php7.0-fpm.service
如果.htaccess不变,php.ini不变,则在根文件夹服务器中搜索.user.ini文件,并搜索upload_max_filesize和post_max_size值并替换它们。
For increasing PHP's file upload limit.
Go to wordpress root directory and open .htaccess file. In my case it was found in /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
2021:
/etc/php/8.0/apache2/php.ini
post_max_size
. The default value is 8M
.sudo service apache2 restart
Try to add this to functions.php
of your theme
@ini_set( 'upload_max_size' , '10M' );
@ini_set( 'post_max_size', '20M');
@ini_set( 'memory_limit', '32M' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.