When an image is uploaded via the media editor the action hook add_attachment
is triggered, with the ID
of the attachment passed as the parameter. You can get full post data for the attachment using the ID
to determine the ID
of the post/page the image is attached to (stored in the post_parent
property). Example code:
add_action( 'add_attachment', 'GoWP_wpse156258' );
function GoWP_wpse156258( $ID ) {
$attachment = get_post( $ID );
$post_id = $attachment->post_parent;
update_post_meta( $post_id, 'your_meta_key', 'your_meta_value' );
}
Hope that helps!