Including an External File in a Post (and Using Processed Paths)

1) Yes, there’s better ways…one would be to use a shortcode instead of storing php in your db. Write and register a shortcode callback that reads your file and returns the content and replace your <?php ... ?> section in the post with the shortcode. Also, you can read the file with file_get_contents();, saves you a few lines of code.

2) You could write a function that simulates that, but the benefit would be too minimal to justify the effort.

BUT: Instead of hardcoding your file path into the shortcode, you can get its path via get_attached_file($attachment_id).