• Resolved sklarwebhost

    (@sklarwebhost)


    I need to be able to keep the original file name that a document has when it is uploaded via a Forminator form. Currently there are random characters added to the beginning of the file name. I know some other form builders provide code snippets to accomplish this, but I couldn’t find any documentation to do so for Forminator. Any help would be greatly appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @sklarwebhost,

    I hope you are keeping well and thank you for reaching out to us.

    Could you please try the following code snippet?

    <?php
    function wpmudev_modify_uploaded_file_name( $filename, $ext, $dir, $unique_filename_callback, $alt_filenames, $number ) {	
    	$uniq_id = substr($filename, 0, 12);
    	if ( ctype_alnum( $uniq_id ) ) {
            $search = $uniq_id.'-';
    		$filename = str_replace(  $search, '', $filename );
    	}
    	
        return $filename;
    }
    
    add_action( 'forminator_form_before_handle_submit', 'wpmudev_uploaded_filename_fix', 10, 1 );
    add_action( 'forminator_form_before_save_entry', 'wpmudev_uploaded_filename_fix', 10, 1 );
    function wpmudev_uploaded_filename_fix( $form_id ) {
    	if ( $form_id != 15 ) { //Please change the form ID
    		return;
    	}
    
    	add_filter('wp_unique_filename', 'wpmudev_modify_uploaded_file_name', 10, 6);
    }

    Please update the form ID in the above code with your form ID. The code could be added using a mu-plugin, please find more details here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    I hope that helps. Please feel free to get back to us if you need clarification.

    Kind Regards,
    Nebu John

    Thread Starter sklarwebhost

    (@sklarwebhost)

    Added the snippet to my child theme’s functions.php file and it works beautifully. Thanks so much for your help and your quick response.

    Plugin Support Laura – WPMU DEV Support

    (@wpmudevsupport3)

    Hi @sklarwebhost

    I’m glad that this issue is resolved.

    If you have a moment, I would very much appreciate it if you could quickly rate our plugin. This will help us keep the plugin available for free.

    https://www.ads-software.com/support/plugin/forminator/reviews/#new-post

    Best Regards
    Laura

    Hello, I’m having the same problem, and I would like to know why the random characters are being added to the upload file name. They are appearing in both the email notification attachment and in the media library file name. I am capable of adding the snippet (I assume to functions.php in my child theme?) but I would like to know the reason for the added characters being added.

    Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @scwtenor,

    I hope you are doing well today!

    You can add the code snippet to your child theme’s functions.php file or you can use it as a mu-plugin.

    You can find more information below on how to use mu-plugins.
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    The random characters added to the upload file name in Forminator are for security and uniqueness purposes.

    1. Security: The random characters help to prevent harmful files from being executed. If, for example, a hacker tries to upload a file with a specific name that’s meant to exploit a known vulnerability, the addition of random characters to the file name will prevent the file from being executed as intended by the hacker.
    2. Uniqueness: It also helps to avoid filename conflicts in the media library. If two users uploaded a file with the same name, the addition of the random characters would help keep both files in the system without any conflicts.

    If you have other questions or need clarification I suggest you to create a new topic.

    Kind regards,
    Zafer

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Prevent Uploaded File Name Change’ is closed to new replies.