<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_46412"> <div class="blockcode"> <div id="code_UPY"><ol> <li> <li><?php<li>/**<li>* PHP取二进制文件头快速判断文件类型<li>*<li>* @param 文件 $file<li>* @return string<li>* @author lrenwang<li>* @blog blog.lrenwang.com<li>*/<li>function get_extname($file)<li>{<li> $fp = fopen($file, "rb");<li> $bin = fread($fp, 2); //只读2字节<li> fclose($fp);<li> $bin_info = @unpack("C2chars", $bin);<li> $code = intval($bin_info['chars1'].$bin_info['chars2']);<li> switch ($code) {<li> case 7790:<li> $type = 'exe';<li> break;<li> case 7784:<li> $type = 'midi';<li> break;<li> case 8075:<li> $type = 'zip';<li> break;<li> case 8297:<li> $type = 'rar';<li> break;<li> case 255216:<li> $type = 'jpg';<li> break;<li> case 7173:<li> $type = 'gif';<li> break;<li> case 6677:<li> $type = 'bmp';<li> break;<li> case 13780:<li> $type = 'png';<li> break;<li> default:<li> $type = $code;<li> break;<li> }<li> return $type;<li>}<li>?></li> </ol></div> <em onclick="copycode($('code_UPY'));">复制代码</em> </div> </td></tr></table> <div id="comment_46412" class="cm"> </div> <div id="post_rate_div_46412"></div> <br><br>