您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php实现通过文件头判断格式的方法

2024/3/1 0:07:49发布15次查看
这篇文章主要介绍了php实现通过文件头判断格式的方法,涉及php文件读取及字符串解析的相关技巧,需要的朋友可以参考下
具体如下:
function judgefile($file,$form){ if(!empty($file) && !empty($form)){ $filehead = fopen($file,'r'); $bin = fread($filehead, 2); fclose($filehead); $data = unpack('c2chars', $bin); $type_code = intval($data['chars1'].$data['chars2']); switch ($type_code) { case 7790: $filetype = 'exe';break; case 7784: $filetype = 'midi';break; case 8075: $filetype = 'zip';break; case 8297: $filetype = 'rar';break; case 255216: $filetype = 'jpg';break; case 7173: $filetype = 'gif';break; case 6677: $filetype = 'bmp';break; case 13780: $filetype = 'png';break; default: $filetype = 'unknown';break; } if(!is_array($form)){ if($filetype==$form){ return true; }else{ return false; } }else{ if(in_array($file, $form)){ return true; }else{ return false; } } }else{ return false; } }
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php中id设置自增后不连续的原因及解决方法
php实现判断手机设备的方法
php strip_tags() 剥去字符串中的 html 标签
以上就是php实现通过文件头判断格式的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product