十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
本文为大家分享了微信小程序人脸识别的具体代码,供大家参考,具体内容如下

首先,我们要有开发者工具,今天所说的是后端和前端联合起来实现的。
在PHP的控制器中写一个upload方法,代码如下:
public function upload($id=''){
if(empty($id)){
return false;
}
$no = M("student")->where("id={$id}")->getField('no');
$dir = "./Upload/studentface/";
if(!file_exists($dir)){
mkdir($dir, 0777, true);
}
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = $dir; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
$upload->saveName = $no;
$upload->replace = true;
$upload->autoSub = false;
// 上传文件
$info = $upload->uploadOne($_FILES['file']);
if(!$info) {// 上传错误提示错误信息
// return $this->ajaxReturn(array('error'=>true,'msg'=>$upload->getError()));
return json_encode(array('error'=>true,'msg'=>$upload->getError()),JSON_UNESCAPED_UNICODE);
}else{// 上传成功 获取上传文件信息
// return $this->ajaxReturn(array('error'=>false,'msg'=>$info['savepath'].$info['savename'],'id'=>$id));
$file = $dir . $info['savepath'] . $info['savename'];
$image = base64_encode(file_get_contents($file));
$this->facevalid($no,$image);
$m = M('head');
$data = $m->where("no='{$no}'")->find();
if($data){
//有数据,则更新
$m->where("no='{$no}'")->save(array('base64'=>$image, 'path'=>$file));
}else{
$m->add(array('no'=>$no,'base64'=>$image,'path'=>$file));
}
return "采集照片成功";
}
} 另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。