码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-05-07 01:03:27      阅读:146      评论:0      收藏:0      [点我收藏+]

标签: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;
}

判断文件的真实类型

本文出自 “php阿超” 博客,请务必保留此出处http://asuper.blog.51cto.com/1622151/1643622

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

标签:php 图片文件 检测

原文地址:http://asuper.blog.51cto.com/1622151/1643622

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!