• Resolved jemsz

    (@jemsz)


    Hello!

    When using the file uploader how do I prevent it from creating various duplicates of the same image? Eg, 100×100 etc

    I just want the original master image uploaded to /uploads/formidable/ folder

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Njones35

    (@njones35)

    Hi there,

    I’m afraid that we are only able to offer support for the Lite plugin via WordPress forums, and all queries about Pro functionality need to go via our helpdesk.

    Since the upload field is a Pro feature, could you please open a ticket here for assistance??https://formidableforms.com/new-topic/

    Best,
    Nathanael

    Hi,

    According to the forum rules, the plugin author couldn’t provide support for premium products. However, as a volunteer, I found a solution that might help you.

    You’ll have to use the frm_after_create_entry hook which runs after a form is submitted and an entry is created. You can find more details here: https://formidableforms.com/knowledgebase/frm_after_create_entry/.

    After the form has been submitted, you can use the PHP glob() function to check if the wp-content/uploads/formidable directory or its subdirectories have any image thumbnails or scaled versions that have been generated. Then, you can use the PHP unlink() function to delete these generated images.

    PHP functions reference:

    1. https://www.php.net/manual/en/function.glob.php
    2. https://www.php.net/manual/en/function.unlink.php

    You can use the following code snippet in your child theme’s functions.php file or use a Code Snippets plugin.

    Code:

    function after_entry_created( $entry_id, $form_id )
    {
     $upload_dir  = wp_upload_dir();
     $upload_path = $upload_dir[ 'basedir' ] . '/formidable/';
    
     // Patterns to match thumbnails
     $thumbnails_pattern = $upload_path . '**/{*-*x*.*,*-scaled.*}';
    
     $thumbnails = glob( $thumbnails_pattern, GLOB_BRACE );
    
     // Delete all thumbnails
     foreach ( $thumbnails as $thumbnail ) {
      if ( is_writable( $thumbnail ) ) {
       unlink( $thumbnail );
      }
     }
    }
    
    add_action( 'frm_after_create_entry', 'after_entry_created', 50, 2 );

    Code Snippets plugin settings:

    Preview:

    Note: Keep in mind that this function will delete all image thumbnails and scaled copies from Formidable Forms. Make sure to back up your website before using this feature.

    https://www.wpbeginner.com/beginners-guide/how-to-backup-your-wordpress-site/

    Give it a try, and let me know how that goes! ??

    Plugin Support Njones35

    (@njones35)

    Thanks for the input @faisalahammad

    That isn’t the advice I would have offered – and I do believe there is a simpler solution, but if @jemsz opens a ticket in our helpdesk, our team will be happy to help.

    Best,
    Nathanael

    Thread Starter jemsz

    (@jemsz)

    Thanking you both for the support!

    Thread Starter jemsz

    (@jemsz)

    Faisal, I’m looking to prevent images duplicating during upload and not post creation. I suspect this might be the reason why the form button will not allow submit for files over 10MB, taking too long ??

    Thank you anyway for the suggestion! I’m going to use this anyway

    • This reply was modified 8 months ago by jemsz.
    Faisal Ahammad

    (@faisalahammad)

    Hi @jemsz,

    I got it now. The Formidable Forms save all post (creation) images in wp-content/uploads/formidable/2, but for form upload media, they are saved in wp-content/uploads/formidable/1.

    So if you just add 1 after the /formidable/ on the 4th line, then it will only apply the code to the 1 folder and will allow the post images to have thumbnails.

    The code will look like this: ??

    $upload_path = $upload_dir[ 'basedir' ] . '/formidable/1';

    Preview:

    Here is the final code: ????

    function after_entry_created( $entry_id, $form_id )
    {
     $upload_dir  = wp_upload_dir();
     $upload_path = $upload_dir[ 'basedir' ] . '/formidable/1';
    
     // Patterns to match thumbnails
     $thumbnails_pattern = $upload_path . '**/{*-*x*.*,*-scaled.*}';
    
     $thumbnails = glob( $thumbnails_pattern, GLOB_BRACE );
    
     // Delete all thumbnails
     foreach ( $thumbnails as $thumbnail ) {
      if ( is_writable( $thumbnail ) ) {
       unlink( $thumbnail );
      }
     }
    }
    
    add_action( 'frm_after_create_entry', 'after_entry_created', 50, 2 );

    I hope that helps. Let me know how that goes! Thank you ????

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Disable Image Variation Creation’ is closed to new replies.