[Resolved] I want to limit max file upload size in WP

Home Forums Support [Resolved] I want to limit max file upload size in WP

Home Forums Support I want to limit max file upload size in WP

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #185490
    Joanne 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 29

    Is 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.
    #185493
    Joanne Smith

    here is the site

    https://www.bobtailclassifieds.com.au

    Joanne

    #185537
    Tom
    Lead Developer
    Lead Developer

    Hi 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;
    }
    #185541
    Joanne Smith

    hm

    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

    Post an Ad

    just in case ??

    Joanne

    #185548
    Joanne Smith

    wait one sec – just noticed that it was NOT ACTIVATED in the plugins — sorry about that

    OK its WORKS

    thanks

    Joanne

    #185549
    Joanne Smith

    One 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

    #185645
    Tom
    Lead Developer
    Lead Developer

    I’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.

    #1758694
    Md Abdullah Al Mamun

    How I can increase my wp media upload size? can I use php.in or other requirements here.

    #1758882
    David
    Staff
    Customer Support

    Hi 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:

    https://docs.generatepress.com/article/using-child-theme/

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.