How to get boolean if file A is attached to post B

Get all attachments:

$attachments = get_posts( array(
'post_type' => 'attachment',
'numberposts' => -1,
) );

Check attachment “parent” for each attachment.

foreach($attachments as $attachment){
$parentID = $attachment->post_parent;
$postID = $post->ID;
if($parentID == $postID){
  //your code here
  echo 'This attachment belongs to the current post.';
  }
}

But if you already have the attachment, all you need is:
note: By “have” i mean you previously queried it or saved it into a object previously.

$parentID = $attachment->post_parent;
$postID = $post->ID;
if($parentID == $postID){
  //your code here
  echo 'This attachment belongs to the current post.';
  }