根据文件头进制特征识别文件类型,识别为图片进行OCR识别,懂得都懂,禁止用于违法行为。
<?php
// 16进制特征码
$checkMap = [
".jpeg" => hex2bin("FFD8FF"),
".png" => hex2bin("89504E47"),
".gif" => hex2bin("47494638"),
".tif" => hex2bin("49492A00"),
".bmp" => hex2bin("424D")
];
// 传递微信加密文件
$file = './be27b0c8911ffd7294b7febc16a9cb91_t.dat';
if (!file_exists($file)) {
throw new Exception('文件' . $file . '不存在');
}
// 读取文件内容
$content = file_get_contents($file);
if (!$content) {
throw new Exception('未获取到文件内容');
}
// 读取文件前10个字节内容作为特征码
$bytesToRead = 10;
$feature = substr($content, 0, 10);
if (!$feature || strlen($feature) != 10) {
throw new Exception('未获取到文件特征码');
}
// 检查特征
$feature_array = str_split($feature, 1);
$fileRes = checkImage($feature_array);
if (empty($fileRes['0'])) {
throw new Exception('不支持的文件类型');
}
// 生成新的文件
$newFile = 'test' . $fileRes['0'];
// 将文件内容转换
$newChar = '';
for ($i = 0; $i < strlen($content); $i++) {
$newChar .= $content[$i] ^ $fileRes['1'];
}
file_put_contents($newFile, $newChar);
// 检查特征
function checkImage($in_feature)
{
global $checkMap;
foreach ($checkMap as $key => $check_feature) {
$isConform = checkConformRule($check_feature, $in_feature);
if ($isConform) {
return [$key, $isConform];
}
}
return [null, null];
}
// 检查规则
function checkConformRule($check_feature, $in_feature)
{
$initDecodeByte = $check_feature[0] ^ $in_feature[0];
for ($i = 0; $i < strlen($check_feature); $i++) {
$b = $check_feature[$i] ^ $in_feature[$i];
if ($b !== $initDecodeByte) {
return false;
}
}
return $initDecodeByte;
}PHP验证码不显示的问题应该是经常的事情,我在这里把2种解决方案都发出来方便大家后期使用.因为是昨天晚上自己写验证码都没有显示,我就直接把之前和李炎恢老师上课写的验证码拿来还是不显示,醉了。首先是第一种方法:1、打开服务器安装目录下的php.ini文件;2、去掉;extension=php_gd.d...
/** * 计算两点地理坐标之间的距离 * @param Decimal $longitude1 起点经度 * @param Decimal $lati...
通过http推送消息给socket,socket服务再向客户端推送<?php /* * Socket推送 * 请用守护进程方式启动php msgservice.php & (socket只...
最近在公司开发一个新的项目假设项目域名是a.com,需要接入b.com的单点登陆系统。(1).首先我们会在a.com的登陆页面用iframe引入b.com来显示登陆界面,实际上登陆验证操作都是在b.com上面(2).当b.com验证通过,会在前端ajax请求a.com的回调地址,这个回调地址目的就是...
<?php /** * daemonize让当前脚本为守护进程执行 * @param string $callback 匿名函数 */ function daemonize($callback) {...
php7新增的特性(1).强制限制只能返回一种类型<?php class task { } //must return an integer function add(): int { &nb...