Well, my knowledge in that matter is purely experimental ;-) i.e. I open the files in binary mode and look at them... A signature is always at the beginning. I can give you some more (in ASCII this time ) :
.gif : GIF
.bmp : BM
.pdf : %PDF
No signature for txt files, all you can do to recognize them is check for non-alphanumeric characters.
A little function in PHP to check signatures :
function CheckSignature($filename,$signature)
{
$f=fopen($filename,"r");
$s=fread($f,strlen($signature));
$Ok=($s==$signature);
fclose($f);
return $Ok;
}
print CheckSignature("somegif.gif","GIF");
print CheckSignature("somjpg.jpg",chr(0xFF).chr(0xD8).chr(0xFF).chr(0xE0));