代码如下 | 复制代码 |
** * * * @access public * @param string filename 文件名 * @param string limit_ext_types 允许的文件类型,用|包围的类型如:|gif|txt| * @return string */ function check_file_type($filename, $limit_ext_types = ''){ $extname = strtolower(substr($filename, strrpos($filename, '.') + 1)); if ($limit_ext_types && stristr($limit_ext_types, '|' . $extname . '|') === false){ return ''; } $str = $format = ''; $file = @fopen($filename, 'rb'); if ($file){ $str = @fread($file, 0x400); // 读取前 1024 个字节 @fclose($file); } else{ $format=$extname; } if ($format == '' && strlen($str) >= 2 ){ if (substr($str, 0, 4) == 'MThd' && $extname != 'txt'){ $format = 'mid'; } elseif (substr($str, 0, 4) == 'RIFF' && $extname == 'wav'){ $format = 'wav'; } elseif (substr($str ,0, 3) == "xFFxD8xFF"){ $format = 'jpg'; } elseif (substr($str ,0, 4) == 'GIF8' && $extname != 'txt'){ $format = 'gif'; } elseif (substr($str ,0, 8) == "x89x50x4Ex47x0Dx0Ax1Ax0A"){ $format = 'png'; } elseif (substr($str ,0, 2) == 'BM' && $extname != 'txt'){ $format = 'bmp'; } elseif ((substr($str ,0, 3) == 'CWS' || substr($str ,0, 3) == 'FWS') && $extname != 'txt'){ $format = 'swf'; } elseif (substr($str ,0, 4) == "xD0xCFx11xE0"){ // D0CF11E == DOCFILE == Microsoft Office Document if (substr($str,0x200,4) == "xECxA5xC1x00" || $extname == 'doc'){ $format = 'doc'; } elseif (substr($str,0x200,2) == "x09x08" || $extname == 'xls'){ $format = 'xls'; } elseif (substr($str,0x200,4) == "xFDxFFxFFxFF" || $extname == 'ppt'){ $format = 'ppt'; } } elseif (substr($str ,0, 4) == "PKx03x04"){ $format = 'zip'; } elseif (substr($str ,0, 4) == 'Rar!' && $extname != 'txt'){ $format = 'rar'; } elseif (substr($str ,0, 4) == "x25PDF"){ $format = 'pdf'; } elseif (substr($str ,0, 3) == "x30x82x0A"){ $format = 'cert'; } elseif (substr($str ,0, 4) == 'ITSF' && $extname != 'txt'){ $format = 'chm'; } elseif (substr($str ,0, 4) == "x2ERMF"){ $format = 'rm'; } elseif ($extname == 'sql'){ $format = 'sql'; } elseif ($extname == 'txt'){ $format = 'txt'; } } if ($limit_ext_types && stristr($limit_ext_types, '|' . $format . '|') === false){ $format = ''; } return $format; } |
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级