You don't really need to check to see what the file type is since the output doesn't change for each... I would just check to see if the $ext exists, and go from there...
if(isset($ext)):
echo "<embed src=\"$dir/$file.$ext\" autostart=\"true\"></embed>";
echo "<br>\n";
echo "<a href=\"java script:history.back()\">Back</a>\n";
Endif;
Anyhow, let me know if this works for you, and if not, let me know what the problem is/are, and we'll go from there...