根据文件头进制特征识别文件类型,识别为图片进行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; }
代码1:for循环批量插入100W数据<?php set_time_limit(0); $servername = "localhost"; $username = "root"; $password ...
function objtoarr($obj){ $ret = array(); foreach($obj as $key =>$value){ if(gettype($value) == 'arr...
//$ak开发密钥,$cityname城市名称(支持省县乡详细地址) public function getposition($ak,$cityname){ $callback=array('lng'=>0,'l...
使用php函数array_multisort()即可实现和SQL一样的order by排序. 例如我们需要对会员表按照主键降序排列,年龄升序排列://会员表数据 $list = []; $list[] = ['mid' =>&n...
【一】.迭代器迭代是指反复执行一个过程,每执行一次叫做一次迭代。比如下面的代码就叫做迭代:1. <?php 2. $data = ['1', '2', &...
<?php //如果支持exec函数,可以使用的方式 exec('chcp 65001'); //如果exec函数因安全问题禁用,可以使用的方式 pclose(popen('chcp 65001', 'r'));...