You can use the Unix <i>file</i> command. Make sure you use the full path to the <i>file</i> command in your script. If you are running on a someone elses server, they will probably not let you run shell commands from within your script. It's kind of a security thing.
But just in case you are running your own site, I just tried this script out and it works.
<?php
$a = /usr/bin/file [filename];
// Note that these are backticks and not apostrophe's
if ( ereg("text",$a)){
echo "This is a text file";
}
elseif ( ereg("executable",$a)){
echo "This is an executable file";
}
else{
echo "This file is neither executable or text type";
}
?>