• Resolved jemigirl

    (@jemigirl)


    Hi. My client is concerned about people uploading large images with their ads. Can we put a max file size limit just on images that are uploaded with this plugin? We don’t want to change our file size limit for the main site.

    Thanks,
    Julie

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, you can limit the max. file upload size using the Limit File Uploads snippet https://github.com/simpliko/wpadverts-snippets/blob/master/limit-file-uploads/limit-file-uploads.php or using the Custom Fields extension https://wpadverts.com/extensions/custom-fields/

    Thread Starter jemigirl

    (@jemigirl)

    Where do I put this snippet?

    Plugin Author Greg Winiarski

    (@gwin)

    You can either copy the code to your theme functions.php file, or as explained here at the bottom https://github.com/simpliko/wpadverts-snippets download the snippet to your computer and then install as a plugin.

    Note that aside of copying the code you will also need to customize it to only limit the max upload size, so in your case the limit_file_upload() function would look like this

    
    function limit_file_uploads( $form ) {
        
        if( $form['name'] != "advert" ) {
            return $form;
        }
        foreach( $form["field"] as $key => $field ) {
            if( $field["name"] != "gallery" ) {
                continue;
            }
            $form["field"][$key]["validator"][] = array(
                "name" => "upload_size",
                "params" => array( 
                    "min_size" => null,     // minimum file size
                    "max_size" => "4MB"     // maximum file size
                )
            );
        }
        return $form;
    }
    
    Thread Starter jemigirl

    (@jemigirl)

    Hi Greg, I have tried this both ways – as a plug-in and in the functions.php file but I can still upload images larger than the max size of 4MB. Is there somethings I am missing?

    Thanks,
    Julie

    Plugin Author Greg Winiarski

    (@gwin)

    Hi, it is possible your server or PHP has a lower limit (usually the file upload limit in PHP is set to 2MB).

    You can ask your server support what are the limits set on file uploads and if they are around 2MB if they can increase them for you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Image upload size’ is closed to new replies.