• Resolved MIGHTYminnow

    (@mightyminnow)


    We have a form creating a post where the user can upload an image which becomes a featured image for the post.

    This works fine if the image has a .jpg (lowercase) extension, but now uppercase .JPG.

    The form throws an error saying the file time is not accepted, no post is created, but confusingly the image gets uploaded all the same.

    How can we make the form ignore the case of the extension?

    For developers and savvy users it may not be a problem, but for less savvy users it would be a block.

    Please advise.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @mightyminnow

    I hope you are doing well.

    I was able to replicate this, I see the plugin will validate those format:

    ( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp' )

    I tried to override this list but unfortunately didn’t work, we pinged our developers to verify if any workaround is possible here.

    We will keep you posted

    Best Regards
    Patrick Freitas

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @mightyminnow ,

    Please try this code snippet:

    
    <?php
    function wpmudev_modify_mime_exts_file( $filename, $filename_raw ) {
        $info 			= pathinfo($filename);
        $ext  			= empty($info['extension']) ? '' : $info['extension'];
        $name 			= basename($filename, $ext);
    	$modified_exts 	= array('JPG', 'PNG', 'JPEG');
    
    	if ( !empty( $ext ) && in_array( $ext, $modified_exts ) ) {
    		$filename = str_replace( $ext, strtolower($ext),  $filename );
    	}
    
        return $filename;
    }
    
    add_action( 'forminator_form_before_save_entry', 'wpmudev_uploaded_filename_mime_check', 10, 1 );
    function wpmudev_uploaded_filename_mime_check( $form_id ) {
    	if( $form_id == 4356 ) {
    		add_filter('sanitize_file_name', 'wpmudev_modify_mime_exts_file', 10, 2);
    	}
    }

    4356 should be changed to your form’s ID.

    This can be used as MU-plugin: https://premium.wpmudev.org/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins

    kind regards,
    Kasia

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @mightyminnow ,

    We haven’t heard from you for 4 days now, so it looks like you no longer need our assistance.

    Feel free to re-open this ticket if required.

    Kind regards
    Kasia

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Image Extension Error’ is closed to new replies.