本文主要介绍如何实现从wechat小程序wx.uploadfile的本地文件到base64的迁移。 本文通过代码说明进行了非常详细的介绍,有一定的参考价值。 有需要的朋友请参考
利用微信小程序wx.uploadfile、PHP接口将本地图像转换为base64位。
网络上到处都是粘贴复制的wx.uploadfile的解决方案,但尚未找到具体代码:
特意给需要的伙伴们:
代码:
case 'imgBufferToBase64':
$data=' ';
file_put_contents(1.txt ),var_export ) $_files,true ).(rn ),FILE_APPEND );
if (! empty $ _ files [ ' upload ' ] [ ' tmp _ name ' ] ] {
if (empty ($ _ files [ ' upload ' ] [ ' type ' ] ) )。
io :调试(“文件类型不正确”);
}
if (! in _ array ($ _ files [ ' upload ' ] [ ' type ' ],array (
' image/gif ',
' image/pjpeg ',
' image/jpeg ',
' image/x-png ',
' image/png ',
' image/bmp '
() ) )
io :3360 debug ($ _ files [ ' upload ' ] [ ' type ' ].'文件类型不正确');
}
$ data=file _ get _ contents $ _ files [ ' upload ' ] [ ' tmp _ name ' ];
file_put_contents('1.txt ',var_export ) $data,true ).'rn ',FILE_APPEND );
io :调试(“分析成功”、true、$data );
}
IO:Debug (“分析失败”);
布雷克;
js代码:
wx.uploadFile({ (
URL : ' https://' app.global data.host '/API/sign=' sign,
文件路径: tempfile paths [0],
名称: ' upload ',
header: {
' content-type ' : ' multipart/form-data ',
' content-type ' : ' application/x-www-form-urlencoded '
(,
格式数据:格式数据、
success :功能(RES ) {
var$data=JSON.parse(RES.data );
if (类型of ) $data.data )!='undefined' $data.code
varimgbase 64=' data : image/JPEG; base64,' $data.data;
}
}
() )
希望以上是正文的全部内容,对大家的学习有帮助。 更多相关内容请关注PHP中文网。
相关建议: