The user of the other question mentions .user.ini
file, which is the equivalent for PHP of what .htaccess
is for Apache, namely a local configuration file.
You are looking for limiting the maximum size of a POST
request, which is the standard type of requests for sending forms/uploading stuff. The php setting you are looking for, is post_max_size
.
Create a .user.ini
in the root of your domain (the one with the wp-config.php
file) and put just this line inside:
post_max_size = 30M
This will make the php script reject any submission which is larger than 30M, also counting text fields and everything. However depending on your upload logic (ajax? direct post?) you have to handle the “upload too large” case. If you are doing a “simple” form submission you will get a 413 Request entity too large
HTTP error. In this case you should consider doing a little apache+htaccess magic and create some customized error pages. If you upload through an ajax submission then you have just to put a simple check in the ajax callback.
Also, you should really put a client-side check before letting the submission: imagine the look on the face of a user that waited whole minutes for a 32M file to upload, only to get an error page in return. Look at this question to learn how to do a client-size check in javascript.
EDIT
If you are using nginx and/or php-fpm above instructions vary slightly, but it’s pretty easy to find the nginx-equivalent settings.