没有合适的资源?快使用搜索试试~ 我知道了~
php通过文件头判断格式的方法
0 下载量 156 浏览量
2020-12-19
16:08:13
上传
评论
收藏 47KB PDF 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/13730183/0001-1e58a906cabfefceef4314c7781ab981_thumbnail.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
1页
本文实例讲述了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
资源详情
资源评论
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/13730183/bg1.jpg)
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格式化美化的排版工具帮助大家在以后的格式化美化的排版工具帮助大家在以后的PHP程序设计中进行代码排版:程序设计中进行代码排版:
php代码在线格式化美化工具:代码在线格式化美化工具:
http://tools.jb51.net/code/phpformat
另外,由于另外,由于php属于属于C语言风格,因此下面这款工具同样可以实现语言风格,因此下面这款工具同样可以实现php代码的格式化:代码的格式化:
C语言风格语言风格/HTML/CSS/json代码格式化美化工具:代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数学运算技巧总结》、《php操作office文档技巧总结(包括
word,excel,access,ppt)》、《PHP数组(Array)操作技巧大全》、《php排序算法总结》、《PHP常用遍历算法与技巧总
结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、《PHP运算与运算符用法
总结》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章您可能感兴趣的文章:php实现的一段简单概率相关代码php获取一定范围内取N个不重复的随机数php时间函数用法分析php使
用number_format函数截取小数的方法分析php中关于长度计算容易混淆的问题分析求PHP数组最大值,最小值的代码php 求质
素(素数) 的实现代码深入理解PHP几个算法:PHP冒泡、PHP二分法、PHP求素数、PHP乘法表PHP求小于1000的所有水
仙花数的代码C语言求圆周率的简单实现方法python计算圆周率pi的方法JavaScript中使用Math.PI圆周率属性的方法php求圆
周率的简单实现方法
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![chm](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_38748239
- 粉丝: 3
- 资源: 943
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0