php 判断图片文件的真实类型

/**
 *  * 检测文件的真实类型
 *   * @param  string $srcPath 文件路径
 *    * @return string $realType 文件真实类型
 *     */

$imgurl = http://pic.babytree.com/foto3/thumbs/2015/0506/51/8/357557aa334dd03923a408f_nb.jpg;


echo file_type_detect($imgurl);
function file_type_detect($srcPath){
    $types = array(
        6677    => bmp,7173    => gif,7368    => mp3,13780   => png,255216  => jpg,);  
    $curl_obj = new cURL(false);
    $binary = $curl_obj->get($srcPath);

    //$binary = file_get_contents($srcPath);
    $bytes = substr($binary,0,2); 
    $head = @unpack(C2char,$bytes);
    $typeCode = intval($head[char1].$head[char2]);
    $realType = isset($types[$typeCode]) ? $types[$typeCode] : $typeCode;
    return $realType;
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...