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

释放双眼,带上耳机,听听看~!
<?php
/**
 * 检测文件的真实类型
 * @param  string $srcPath 文件路径
 * @return string $realType 文件真实类型
*/

$imgurl = 'https://ae01.alicdn.com/kf/HTB1w5xdS4TpK1RjSZR0762EwXXa7.png';
echo file_type_detect($imgurl);
function file_type_detect($srcPath){
    $types = array(6677    => 'bmp',7173    => 'gif',7368    => 'mp3',13780   => 'png',255216  => 'jpg',);  

    $binary = curl_get($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;
}
function curl_get($url){
    $ch=curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn; R815T Build/JOP40D) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.5 Mobile Safari/533.1');
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $content=curl_exec($ch);
    curl_close($ch);return($content);
}

人已赞赏
首页

ArtQRCode艺术二维码生成js插件

2019-12-18 22:57:38

首页

WordPress音乐歌单插件[网易云音乐]

2019-12-18 22:59:39

现在起,让您的站点焕然一新

SSpanel-Malio主题,不仅仅是好看

如果点击咨询购买按钮无法唤起QQ,请手动添加QQ2130482224(请注明主题咨询)
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索