根据文件头进制特征识别文件类型,识别为图片进行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;
}/** * 计算两点地理坐标之间的距离 * @param Decimal $longitude1 起点经度 * @param Decimal $lati...
<?php /* *算法学习自百度.只是学习和记录 */ header("Content-type:text/html;charset=utf-8"); //1.设置奖项,id是奖项id,name是中奖名称,v是中奖概率 $arr =&n...
在PHP中,大部分变量类型,如字符串,整型,浮点,数组等都是值类型的,而类和对象是引用类型.和其他语言有点差距.(1).在值类型中我们直接使用&符号表示指向对应变量的内存地址,当前变量和被指向的变量只要有1个的值被修改都会直接影响另外一个变量的值发生变化。(ps:还是非常节省内存的,可以使用...
001源码:/* * $xml_str是xml字符串 */ function xmltoarray($xml_str) { //禁止XML实体扩展攻击 libxml_disable_entity_loader(true); //拒绝包含...
php多进程应用场景主要是非web端,fpm下是不支持多进程的,非类linux操作系统都不支持,请在cli模式使用.可以使用多进程做任务分发,批量计算,批量文件处理,批量爬虫,网络运维等等。下面看一份简单的入门demo//创建子进程 $pid=pcntl_fork(); //返回-1,创建失败,不...
PHP不像net支持多继承,自身只支持单继承,为了解决这个问题,php出了Trait这个特性,减少单继承语言的限制。并且能让代码复用率更高。说白了就是一个对象的属性和方法扩展工具一样。例如:trait exts { public f...