Insert attachments from front end form

I found a working solution. This handles the uploaded files by attaching them to the post and display them in the loop. Still no featured image is set.

if ( $_FILES ) {
    foreach ( $_FILES as $file => $array ) {
        $newupload = insert_attachment( $file, $pid_buy );
    }
}

function insert_attachment( $file_handler, $post_id, $setthumb='false' ) {

    if ( $_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK ) {
        __return_false();
    }
    require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
    require_once( ABSPATH . "wp-admin" . '/includes/file.php' );
    require_once( ABSPATH . "wp-admin" . '/includes/media.php' );
    $attach_id = media_handle_upload( $file_handler, $post_id );
    return $attach_id;
}

function show_all_thumbs() { // displaying the attached thumbs
    global $post;
    $post = get_post( $post );
    /* image code */
    $images =& get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent=" . $post->ID );
    if ( $images ){
        foreach ( $images as $imageID => $imagePost ){
            unset( $the_b_img );
            $the_b_img  = wp_get_attachment_image( $imageID, "thumbnail', false );
            $thumblist .= '<a href="'.get_attachment_link($imageID).'">'.$the_b_img.'</a>';
        }
    }
    return $thumblist;
}