Insert attachment ID in custom field from media uploader

This is what I want to do:

  1. In the media uploader, add a link “Use this attachment ID as custom field“.
  2. Add the attachment ID in a custom fields meta box.

I’ve searched for hours for a plugin that does this but found nothing. Code examples, plugins, hints. Anything might be helpful.

Solutions Collecting From Web of "Insert attachment ID in custom field from media uploader"

When you upload attachments to a post/page they become child elements of that post/page.

What you can do is provide a drop down in your custom field to list all uploaded files to the uploader for the current post/page. This is the code I used to show a list of files so the user could select which one was a floor plan image:

      <select name="chb_homes_for_sale_specifics_floor_plan" style="width:100%;">
        <option value="" <?php selected($custom["chb_homes_for_sale_specifics_floor_plan"][0], ""); ?>>No Floor Plan</option>
        $args = array(
            'numberposts'     => -1,
            'orderby'         => 'menu_order',
            'order'           => 'ASC',
            'post_type'       => 'attachment',
            'post_parent'     => $post->ID,
            'post_mime_type' => 'image'
        $image = get_posts($args);
        if($image) {
            foreach($image as $key => $data) : ?>

                <option value="<?php echo $data->ID; ?>" <?php selected($custom["chb_homes_for_sale_specifics_floor_plan"][0], $data->ID); ?>><?php echo basename ( get_attached_file( $data->ID ) ); ?></option>

            <?php endforeach;