I don't really understand your question. But I think you're trying to make the browser display html tags as-is instead of reading them as real html. If so, then that's easy: Just use php to replace > and < characters in the output with > and <, respectively.
<?php
//For example, change this:
echo "$filecontents";
//to this:
$filecontents = str_replace('<', '<', $filecontents);
$filecontents = str_replace('>', '>', $filecontents);
echo "$filecontents";
?>
That should fix your problem with html files. I don't really understand the problem with .doc and .pdf files, though, because I don't know the way they're encoded