How to display the maximum upload size in a WordPress single site?
I'm working on a WordPress single site, where in front end, below a custom made form, where I have a file upload feature, I need to display the maximum upload size.
In my local Laragon WAMP setup, the PHP post_max_size
is set to 2G
. I wanted to downgrade to only 20M
(20 mb).
After searching and reading several blog articles, I put the following code in my theme's functions.php
:
?php
// Set upload size limit to 20mb.
@ini_set('upload_max_size', '20M');
@ini_set('post_max_size', '20M');
@ini_set('max_execution_time', '300');
/**
* Filter the upload size limit for non-administrators.
*
* @param string $size Upload size limit (in bytes).
*
* @return int Filtered size limit.
*/
function wpse_control_upload_size_limit( $size ) {
if ( ! current_user_can( 'manage_options' ) ) {
return 20971520; // 20mb to binary bytes.
}
return $size;
}
add_filter( 'upload_size_limit', 'wpse_control_upload_size_limit', 20 );
With this code in action, with a non-admin user I can see the Admin panel Upload New Media page is showing: Maximum upload file size: 20 MB.
Issue is: I want to display the same maximum file size limit information on my front end from.
What I tried so far is putting the following code in functions.php
:
var_dump(@ini_get('post_max_size'));
But this is getting the 2G
limit as it's not getting the WordPress setup.
I also tried by hooking this code in upload_size_limit
with no luck:
add_action( 'upload_size_limit', function() {
var_dump( @ini_get( 'post_max_size' ) );
});
I know there's a plugin named Increase Maximum Upload File Size, but I don't want to use a plugin for this feature. I'm also aware that, in multisite we've setup data from where we can get the maximum upload size.
But how can I display the maximum upload size on a front page form in single WordPress instance?
Topic media-settings uploads Wordpress
Category Web