Last Updated on 2022-07-17 by Clay
Problem
Today, when I tried to upload the client's theme on the test site, that display a rotating circle, and then reported to me the following error message:
The Link You Followed Has Expired.
This error message is so vague that I thought for a while that the uploaded theme file was broken, or the Internet seed was slow... After checking the file, testing the Internet speed, I found the answer is the WordPress limits the upload size.
What does that mean? it's actually quite simple. We can see the file upload limit for the current site form Media > Add New.
As you can see, the current website upload limit is 2MB, which is also the default size of the WordPress upload limit.
If you want to adjust the upload limit, you can refer: [WordPress] How to Change the Upload File Maximum Size Limit
A simplified version of the notes follows.
Change Upload Limit
There are several ways to edit:
- Edit functions.php
- Edit .htaccess
- Edit php.ini
- Add setting to docker-compose.yml (For users who use
docker-compose
to set up WordPress)
Method 1: Edit functions.php file
functions.php is locate at the theme folder.
Add the following settings at the bottom.
@ini_set( 'upload_max_filesize', '20M' ); // 單一檔案大小上限
@ini_set( 'post_max_size', '20M'); // POST 資料大小上限
@ini_set( 'memory_limit', '64M' ); // 記憶體上限
@ini_set( 'max_execution_time', '300' ); // 執行時間上限(s)
Method 2: Edit .htaccess file
.htaccess is locate at the website root directory.
Add the following settings at the bottom.
@ini_set( 'upload_max_filesize', '20M' ); // 單一檔案大小上限
@ini_set( 'post_max_size', '20M'); // POST 資料大小上限
@ini_set( 'memory_limit', '64M' ); // 記憶體上限
@ini_set( 'max_execution_time', '300' ); // 執行時間上限(s)
Method 3: Edit php.ini file
The php.ini file is not simply adding settings, but finding the corresponding settings and modifying values.
upload_max_filesize = 20M
post_max_size = 20M
memory_limit = 64M
max_execution_time = 300
Method 4: Add Settings to docker-compose.yml
Create a new file uploads.ini at the same folder with docker-compose.yml, then write in:
file_uploads = On
memory_limit = 500M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 600
Then add in docker-compose.yml:
volumes:
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
The schema for this volumes is located at:
services:
└ wordpress:
└ volumes:
Then execute the following program:
sudo docker-compose up -d --build
After the above method is successfully modified, you should be able to see the updated value in Media > Add New:
If you still can't modify it successfully, you may have to try other methods.
References
- https://www.viralpatel.net/local-wordpress-docker/
- https://kinsta.com/blog/increase-max-upload-size-wordpress/
- https://www.cloudways.com/blog/increase-media-file-maximum-upload-size-in-wordpress/