根据文件头进制特征识别文件类型,识别为图片进行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;
}001源码:/* * $xml_str是xml字符串 */ function xmltoarray($xml_str) { //禁止XML实体扩展攻击 libxml_disable_entity_loader(true); //拒绝包含...
上篇文章已经讲解arrayacces的原理,现在来讲解下arrayaccess的实际应用。一个大型的互联网项目中必然会存在各种配置信息,例如多种数据库信息:mysql,tidb,mongodb,redis,某个业务模块单独的配置信息如比例,额度等等,那么该如何治理配置信息?PHP项目中大部分的框架都...
(1).在PHP中可以查看的环境变量包括: (1.1).电脑环境变量 (2.1).服务器环境变量(2).getenv()函数获取一个环境变量的值.参数1是环境变量的key,参数2值为true的时候仅从你的电脑环境变量中查找,参数2值为false会从两种变量中全部查询//获取我电脑登录的用户名,输出A...
<?php $member = new class { public function getInfo() { ...
最近在编写windows php多线程的东西,从官网下载了PHP的线程安全版,尝试开启curl扩展extension=php_curl.dllphp -m 却提示 PHP Startup: Unable to load dynamic library 'C:\php\ext\php_curl...
有时候我们需要爬一个接口,但是这个接口需要很多参数,包括header和cookie要去编写,使用php curl模拟实在太慢。我们可以通过浏览器的network来复制请求为curl命令。例如我需要模拟请求接口地址:https://www.xkmz.cc/Ajax/Debug/delly,我们只需要在...