代码如下 | 复制代码 |
/*通过文件名,获得文件类型* *@author chengmo* *@copyright cnblog.com/chengmo 2010-10-17 *@version 0.1 *$filename="d:/1.png";echo cfiletypecheck::getfiletype($filename); 打印:png */ class cfiletypecheck { private static $_typelist=array(); private static $checkclass=null; private function __construct($filename) { self::$_typelist=$this->gettypelist(); } /** *处理文件类型映射关系表* * * @param string $filename 文件类型 * @return string 文件类型,没有找到返回:other */ private function _getfiletype($filename) { $filetype="other"; if(!file_exists($filename)) throw new exception("no found file!"); $file = @fopen($filename,"rb"); if(!$file) throw new exception("file refuse!"); $bin = fread($file, 15); //只读15字节 各个不同文件类型,头信息不一样。 fclose($file); $typelist=self::$_typelist; foreach ($typelist as $v) { $blen=strlen(pack("h*",$v[0])); //得到文件头标记字节数 $tbin=substr($bin,0,intval($blen)); ///需要比较文件头长度 if(strtolower($v[0])==strtolower(array_shift(unpack("h*",$tbin)))) { return $v[1]; } } return $filetype; } /** *得到文件头与文件类型映射表* * * @return array array(array('key',value)...) */ public function gettypelist() { return array(array("ffd8ffe1","jpg"), array("89504e47","png"), array("47494638","gif"), array("49492a00","tif"), array("424d","bmp"), array("41433130","dwg"), array("38425053","ps教程d"), array("7b5c727466","rtf"), array("3c3f786d6c","xml"), array("68746d6c3e","html"), array("44656c69766572792d646174","eml"), array("cfad12fec5fd746f","dbx"), array("2142444e","pst"), array("d0cf11e0","xls/doc"), array("5374616e64617264204a","mdb"), array("ff575043","wpd"), array("252150532d41646f6265","eps/ps"), array("255044462d312e","pdf"), array("e3828596","pwl"), array("504b0304","zip"), array("52617221","rar"), array("57415645","wav"), array("41564920","avi"), array("2e7261fd","ram"), array("2e524d46","rm"), array("000001ba","mpg"), array("000001b3","mpg"), array("6d6f6f76","mov"), array("3026b2758e66cf11","asf"), array("4d546864","mid")); } public static function getfiletype($filename) { if(!self::$checkclass) self::$checkclass=new self($filename); $class=self::$checkclass; return $class->_getfiletype($filename); } } |
创造与魔法 安卓版v1.0.0750
创造与魔法是一款开放世界手游,在游戏中玩家可探索这个奇妙的世
创造与魔法修改版 最新版v1.0.0750
创造与魔法无限点券版是款探索冒险游戏,该款游戏的操作还是蛮自
战争与文明官方版本 安卓版v1.7.16
战争与文明是一款由上海邮通科技有限公司开发的战争策略游戏,这
迷你世界0元领皮肤无限迷你币版 最新安卓版v1.43.0
迷你世界0元购买皮肤版是这款开放沙盒冒险建造游戏的特殊破解版
创造与魔法无限经验版 安卓版v1.0.0750
创造与魔法无限经验版是款可以改造环境,整个游戏的自由度还是蛮