<?php
/*
* 判断文件是不是图片格式
* @param fileName 文件名
* @return array 如果code为1,是图片;否则不是图片
* @author lee complet@163.com
*/
function isImg($fileName) {
$file = fopen($fileName, "rb");
$bin = fread($file, 2); // 只读2字节
fclose($file);
$strInfo = @unpack("C2chars", $bin);
$typeCode = intval($strInfo['chars1'] . $strInfo['chars2']);
$fileType = array();
if ($typeCode == 255216) {
$fileType = array('code' => 1, 'type' => 'jpg');
} elseif ($typeCode == 7173) {
$fileType = array('code' => 1, 'type' => 'gif');
} elseif ($typeCode == 13780) {
$fileType = array('code' => 1, 'type' => 'png');
} else {
$fileType = array('code' => 0, 'type' => '非图片格式');
}
return $fileType;
}
网站题目:php判断上传文件是不是图片,如果是,返回图片格式
浏览路径:https://www.cdcxhl.com/article4/jsoioe.html
成都网站建设公司_创新互联,为您提供用户体验、服务器托管、网站改版、移动网站建设、关键词优化、网页设计公司
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联