21,886
社区成员
发帖
与我相关
我的任务
分享
//打开输出缓冲区并获取远程图片
ob_start();
$context = stream_context_create(
array('http' => array(
'follow_location' => false // don't follow redirects
))
);
readfile($imgUrl, false, $context);
$img = ob_get_contents();
ob_end_clean();
preg_match("/[\/]([^\/]*)[\.]?[^\.\/]*$/", $imgUrl, $m);
function checkFileType($fileName){
$file = fopen($fileName, "rb");
$bin = fread($file, 2); //只读2字节
fclose($file);
$strInfo = @unpack("C2chars", $bin);// C为无符号整数,网上搜到的都是c,为有符号整数,这样会产生负数判断不正常
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
$fileType = '';
if($typeCode == 255216 /*jpg*/ || $typeCode == 7173 /*gif*/ || $typeCode == 13780 /*png*/) {
return true;
}else{
return false;
}
}
$d = ',GIF,JPG,PNG,SWF,PSD,BMP,TIFF,TIFF,JPC,JP2,JPX,JB2,SWC,IFF,WBMP,XBM';
$t = getimagesize('http://avatar.csdn.net/1/8/4/1_hongendazhang.jpg');
echo explode(',',$d)[$t[2]];//JPG