Update media library image shown in “attachment details” when using wp_insert_attachment to add item to the media library

Hello Mike can you check that folder is the image is there which you have uploaded and if yes then when you click on attachment details then on right there is a key which shows File URL: can you check that.if it is empty or wrong path to show.

If file is not there you can use wp_upload_bits to move the file as wp_insert_attachment not move the files automatically.

If still not works can you check your wp_posts and wp_postmeta table for that particular attachment for correct path.

I have tried this code and it successfully works please check

    // set filename
    $upload_path = GFFormsModel::get_upload_path( $entry[ 'form_id' ] );
    $upload_url = GFFormsModel::get_upload_url( $entry[ 'form_id' ] );
    $filename_verbose = str_replace( $upload_url, $upload_path, $entry[ '1' ] );
    $filename_backslashes = trim( $filename_verbose, ' "[] ');
    $filename = stripslashes( $filename_backslashes );

    // check the type of file. We'll use this as the 'post_mime_type'
    $filetype = wp_check_filetype( basename( $filename ), null );

    // Get the path to the upload directory.
    $wp_upload_dir = wp_upload_dir();

    // Prepare an array of post data for the attachment.
    $attachment = array(
        'guid'           => $wp_upload_dir['url'] . "https://wordpress.stackexchange.com/" . basename( $filename ),
        'post_mime_type' => $filetype['type'],
        'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
        'post_content'   => '',
        'post_status'    => 'inherit'
    );

    // create a file in the upload folder
    $upload = wp_upload_bits( basename ( $filename ), null,  file_get_contents( $filename ));

    // Insert the attachment.
    $attach_id = wp_insert_attachment( $attachment, $upload['file'] );

    // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
    require_once( ABSPATH . 'wp-admin/includes/image.php' );

    // Generate the metadata for the attachment, and update the database record.
    $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] );
    wp_update_attachment_metadata( $attach_id, $attach_data );

If still there is issue please post your post and post meta result with Admin file url.