[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 7 posts - 1 through 7 (of 7 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 4 years, 9 months ago by Joanne Smith.
    • This topic was modified 4 years, 9 months 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

    https://www.bobtailclassifieds.com.au/adverts/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.

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