• Resolved Fody

    (@fodisery)


    How to set max number of images uploaded by user for single post?

    Currently its easy to use all server resources.

    Currently I can upload up to 50 images when creating an ad. Maybe someonec can upload thousand of images?

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

    (@gwin)

    It is possible to customize the allowed number, size and etc. of the uploaded images using the Custom Fields extension https://wpadverts.com/extensions/custom-fields/

    It is also possible to do that with the Forms API, for example adding the code below in your theme functions.php file will limit the number of allowed file uploads to 5

    
    add_filter( "adverts_form_load", "limit_file_uploads" );
    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();
          
            // Set minimum and maximum nuber of files user can upload.
            // Note. setting the "min" value basically makes the gallery a required field.
            $form["field"][$key]["validator"][] = array(
                "name" => "upload_limit",
                "params" => array( 
                    "min" => 0,     // minimum files to upload
                    "max" => 5      // maximum file uploads
                )
            );
            break;
        }
        return $form;
    }
    
    Thread Starter Fody

    (@fodisery)

    @gwin Isnt it just add parameter to the frontend html?

    I think its not so safe, hacker just can tamper the posted data, and manually set the data.

    Is there anyway to check the number of images in the backend before submit?

    Plugin Author Greg Winiarski

    (@gwin)

    I am not sure what do you mean?

    The above code is run in the backend when the user goes from the Form to Preview so even if he can somehow bypass the other backend validator when actually uploading a file there would be another validator checking if the number of uploads is correct before showing the preview.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Set max number of images’ is closed to new replies.