- This topic has 8 replies, 2 voices, and was last updated 2 years, 11 months ago by David.
-
AuthorPosts
-
April 9, 2016 at 6:11 am #185490Joanne Smith
Theme Functions (functions.php)
Select theme to edit:I added a new plugin to created a limit upload with some php code by the developer of another plugin on my site — he said to add it to your theme function php — you said to create your own plugin as the theme gets updates and then the PHP script I added gets deleted.
This is the CODE and below is the ERROR message
add_filter("adverts_gallery_upload_prefilter", "limit_file_uploads"); function limit_file_uploads( $file ) { if ( !isset($file["name"]) || !isset($file["type"]) ) { return $file; } if ( !isset( $_POST["post_id"] ) ) { $post_id = 0; } else { $post_id = intval($_POST["post_id"]); } if( $file["size"] >= 1000000 ) { $file["error"] = "Your file is to big."; } return $file; }
I created a new plugin
and got this error message
Fatal error: Cannot redeclare limit_file_uploads() (previously declared in
/home/bobtail/www/www/wp-content/plugins/limit_file_uploads/limit_file_uploads.php:16)
in /home/bobtail/www/www/wp-content/plugins/max-file-upload/max-file-upload.php on line 29Is there any other way you can think of that would limit the file size being uploaded on the site ?
- This topic was modified 8 years ago by Joanne Smith.
- This topic was modified 8 years ago by Tom.
April 9, 2016 at 6:12 am #185493Joanne SmithApril 9, 2016 at 8:39 am #185537TomLead DeveloperLead DeveloperHi Joanne,
This is why it’s always good to prefix functions to avoid conflict.
So you could do this instead:
add_filter("adverts_gallery_upload_prefilter", "joanne_limit_file_uploads"); function joanne_limit_file_uploads( $file ) { if ( !isset($file["name"]) || !isset($file["type"]) ) { return $file; } if ( !isset( $_POST["post_id"] ) ) { $post_id = 0; } else { $post_id = intval($_POST["post_id"]); } if( $file["size"] >= 1000000 ) { $file["error"] = "Your file is to big."; } return $file; }
April 9, 2016 at 8:50 am #185541Joanne Smithhm
I added this code to the site as a plugin and activated it
I tried a test UPLOAD of a 1.3MB image and it did not give me the error message
Can you test a dummy upload (( you don’t have to submit )) just go to the upload button
just in case ??
Joanne
April 9, 2016 at 9:17 am #185548Joanne Smithwait one sec – just noticed that it was NOT ACTIVATED in the plugins — sorry about that
OK its WORKS
thanks
Joanne
April 9, 2016 at 9:31 am #185549Joanne SmithOne other thing ??
Why does it take 3 to 5 mins of SPINNING wheel before the error message comes up ??
Is it the script or something else ??
If you have the plugin turned off it only takes 30 secs to upload and image 2.5MB
hmmm strange
Joanne
April 9, 2016 at 10:44 pm #185645TomLead DeveloperLead DeveloperI’m afraid I wouldn’t know, it would be better to ask the develop as they have an understanding of what’s going on behind the scenes.
May 1, 2021 at 2:04 am #1758694Md Abdullah Al MamunHow I can increase my wp media upload size? can I use php.in or other requirements here.
May 1, 2021 at 5:54 am #1758882DavidStaffCustomer SupportHi there,
that is core WP and server level requirement – you can see some general advice on doing so here:
https://www.wpbeginner.com/wp-tutorials/how-to-increase-the-maximum-file-upload-size-in-wordpress/
But you should check with your host in case they have imposed any limits on that size. Or they may have a simple option to change it in their server control panel
If adding to a functions.php file then you MUST NOT edit the Theme files. You would need to install a child theme:
-
AuthorPosts
- You must be logged in to reply to this topic.