Getting media library popup in custom plugin admin page

There’s a few things to consider, like where you’re putting this… …you didn’t specify so here’s how it would work in a custom post-type:

First you’d have to add the metabox and the inputs to upload the file, then make sure that everything gets saved…

<?php
function add_your_custom_posttype_metaboxes() {
    //you have to set the above function as the the metabox callback in your CPT register
    add_meta_box(
        'upload_image',
        'Upload Image',
        'upload_image',
        'your_custom_posttype',
        'normal',
        'high'
    );
}
function upload_image( $post_object ) {
    wp_nonce_field( basename( __FILE__ ), 'upload_image_fields' ); 
    $uploaded_img           = get_post_meta( $post_object->ID, 'uploaded_img', true );
?>
    <table class="form-table">
        <tr>
            <th>
                <label><?php _e( 'Upload Image', 'textdomain' ); ?></label>
            </th>
            <td>
                <input type="text" class="large-text" name="uploaded_img" id="uploaded_img" value="<?php echo esc_attr( $uploaded_img ); ?>"/>
                <button type="button" class="upload-image-button" id="uploaded_img_btn" data-media-uploader-target="#uploaded_img">
                    <?php _e( 'Upload Image', 'textdomain' )?>
                </button>
                <!-- //The followin line is optional. -->
                <small><?php _e( 'I usually like to add some instructions below an option I have created for a CPT.', 'textdomain' ); ?></small>
            </td>
        </tr>
    </table>
<?php
}
function upload_image_savedata( $post_id, $post ) {
    if( !current_user_can( 'edit_post', $post_id ) ) {
        return $post_id;
    }
    if( !isset( $_POST['upload_image_fields'] ) || !wp_verify_nonce( $_POST['upload_image_fields'], basename(__FILE__) ) ) {
        return $post_id;
    }
    $uploaded_image_meta['uploaded_img']        = esc_textarea( $_POST['uploaded_img'] );
    
    foreach( $uploaded_image_meta as $key => $value ) :
        if( 'revision' === $post->post_type ) {
            return;
        }
        if( get_post_meta( $post_id, $key, false ) ) {
            update_post_meta( $post_id, $key, $value );
        } else {
            add_post_meta( $post_id, $key, $value);
        }
        if( !$value ) {
            delete_post_meta( $post_id, $key );
        }
    endforeach;
    return $post_id;
}
add_action( 'save_post', 'upload_image_savedata', 1, 2 );
?>

Next, you have to add some JS to get the media uploader to launch when you click the button… so in a new file in your plugin called your-js-file.js which I’d put in a /js/ directory to keep things neat and tidy, you’d add the following:

(function( $ ) {
    'use strict';
    $( document ).ready( function() {
        if( $( '#uploaded_img_btn' ).length ) { //checks if the button exists
            var metaImageFrame;
            $( 'body' ).click( function( e ) {
                var btn = e.target;
                if ( !btn || !$( btn ).attr( 'data-media-uploader-target' ) ) return;
                var field = $( btn ).data( 'media-uploader-target' );
                e.preventDefault();
                metaImageFrame = wp.media.frames.metaImageFrame = wp.media( {
                    button: { text:  'Use this file' },
                } );
                metaImageFrame.on( 'select', function() {
                    var media_attachment = metaImageFrame.state().get( 'selection' ).first().toJSON();
                    $( field ).val( media_attachment.url );
                } );
                metaImageFrame.open();
            } );
        }
    } );
} )( jQuery );

Now that that file is done we have to make sure we’re including it in the admin screen for the custom post type and when you enqueue that file you also want to enqueue the WP media uploader scripting…

function your_custom_posttype_admin_scripts() {
    global $post_type;
    if( 'your_custom_posttype' == $post_type ) {
        wp_enqueue_media();
        //you should probably define your plugin version somewhere so you can use it instead of manually changing the 1.0 below every time you update
        wp_enqueue_script( 'cpt-admin-script', plugins_url( 'js/your-js-file.js', __DIR__ ), array( 'jquery' ), '1.0', true );
    }
}
add_action( 'admin_enqueue_scripts', 'your_custom_posttype_admin_scripts' );

So what you get now is an input field with a button that will launch and interact with the default WP media uploader. It’ll then add the URL of the media file to the input and save it when you update the post.

I don’t know where specifically you wanted to include this so I took a guess, but the principal of using an input and button and adding scripting that depends on the WP media script is pretty exactly the same anywhere you want to use it within the admin.