problem with updating metabox of upload image

I have no time to write at your code, but with your help works for me

function wms_add_headerimage_cb( $post ){
//campuri
$values = get_post_custom( $post->ID );

$headerpageimage        = isset( $values['headerpageimage'][0] ) ? esc_attr( $values['headerpageimage'][0] ) : '';
$img_src                = wp_get_attachment_image_src( $headerpageimage, 'medium' );

wp_nonce_field( 'allpages_meta_box', 'allpages_meta_box_nonce' );
?>
    <p>
        <img id="headerpage_image" src="https://wordpress.stackexchange.com/questions/182634/<?php echo $img_src[0] ?>" style="max-width:100%;" />
        <input type="hidden" name="headerpageimage" id="headerpageimage" value="<?php echo $headerpageimage; ?>" />

    <a title="<?php esc_attr_e( 'Set image' ) ?>" href="#" id="set-book-image"><?php _e( 'Set image' ) ?></a>
    <a title="<?php esc_attr_e( 'Remove image' ) ?>" href="#" id="remove-headerpageimage" style="<?php echo ( ! $headerpageimage ? 'display:none;' : '' ); ?>"><?php _e( 'Remove image' ) ?></a>
</p>
<script type="text/javascript">
jQuery(document).ready(function($) {

    // save the send_to_editor handler function
    window.send_to_editor_default = window.send_to_editor;

    $('#set-book-image').click(function(){

        // replace the default send_to_editor handler function with our own
        window.send_to_editor = window.attach_image;
        tb_show('', 'media-upload.php?post_id=<?php echo $post->ID ?>&amp;type=image&amp;TB_iframe=true');

        return false;
    });

    $('#remove-headerpageimage').click(function() {

        $('#headerpageimage').val('');
        $('img').attr('src', '');
        $(this).hide();

        return false;
    });

    // handler function which is invoked after the user selects an image from the gallery popup.
    // this function displays the image and sets the id so it can be persisted to the post meta
    window.attach_image = function(html) {

        // turn the returned image html into a hidden image element so we can easily pull the relevant attributes we need
        $('body').append('<div id="temp_image">' + html + '</div>');

        var img = $('#temp_image').find('img');

        imgurl   = img.attr('src');
        imgclass = img.attr('class');
        imgid    = parseInt(imgclass.replace(/\D/g, ''), 10);

        $('#headerpageimage').val(imgid);
        $('#remove-headerpageimage').show();

        $('img#headerpage_image').attr('src', imgurl);
        try{tb_remove();}catch(e){};
        $('#temp_image').remove();

        // restore the send_to_editor handler function
        window.send_to_editor = window.send_to_editor_default;

    }

});
</script>
<?php

}

add_action( ‘save_post’, ‘headerimage_save’ );
function headerimage_save( $post_id ){

if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
if( !isset( $_POST['allpages_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['allpages_meta_box_nonce'], 'allpages_meta_box' ) ) return $post_id;    
if( !current_user_can( 'edit_post' ) ) return $post_id;  
$allowed = array(   
    'a' => array( // on allow a tags  
        'href' => array() // and those anchors can only have href attribute  
    )  
);

// quantity Icon
if( isset( $_POST['headerpageimage'] ) )  update_post_meta( $post_id, 'headerpageimage', esc_attr( $_POST['headerpageimage']) );

}