这仅适用于PHP> = 5.3.0,并不是100%可靠的,但嘿,这很贴近.
// return mime type ala mimetype extension $finfo = finfo_open(FILEINFO_MIME); //check to see if the mime-type starts with 'text' return substr(finfo_file($finfo,$filename),4) == 'text';