Base64编码,我想大家应该很熟悉了,早期的电子邮件编码,现在的网页图片编码等,都采用了base64编码,来对字符串或者二进制数据流进行转码,以便于传输,在脚本模型中,分别提供了以下几个内置函数,以支持这些操作:
base64('123456',true/false); |<?base64('123456',true);'|'base64('MTIzNDU2',false);?> <? $f:=Base64toFile('iVBORw0KGgoAAAANSUhEUgAAABMAAAARCAYAAAA/mJfHAAACz0lEQVQ4jXVUz2sTQRh9s7M/kiba' +'1KZSCq0HCQgteLMexINUL6KCIngQpFLBg/+A3kTPIiheFJGi4klPKl6sF7G11Wqp1FKkbWKsSW2y' +'TTfNZrM74+xOzKatHfKYH+R7+77vfTOkWq1ybBo/F6cwOfoM8zNvYRWyqJSKYDUPED/CDXT3HseZ' +'SzfR2Z1qxKyWqiCO4zTIOOf4/GEYlrmAzPc3yGemARcBSfO8vs4Rj7RgYOgu9h85F8QWijZU27Yb' +'7F8/DiOqE2Smn8AuFbDT0AG1TkTrswJEwRGjHibuXwb1XPQdPQ/PZSC5XC5Qll14j4r5DempR3DK' +'pgzcBopQGKdKsHZFYodvjMCN7JHKGPOw9OMVUJ4FdcuIUk3kjG3hi0wYFIpYcMIx9/g6egYfSLKV' +'pS9QaxlU1+YRoSIvJtPZAiJBFYKdqgq1vrdn3qG4lIVaqVRQ+j0GpZKDHhQoDArQPIj0ICZS9Ml0' +'Rf6BR2NIT45IMtfKIOJY4uO0bmsTGlZLcM93UhNkGgxG5LmhYjE9J8k8uwziKfKzPhjCddMZF4gI' +'NSpT0aoaUF0i0xfOUtsRparV4LEdcKs+mbLROQ8b9sT1U6SiGBQaMUL1jjAx2QlF13VoiT5oXg06' +'0SWUOshGaAK2Q5EUNQITPcj1YGarZbB9/VC7urrgJk+gmn+KWEtcqqj9p7/qZy2EoiNiyDMmla1F' +'dyO2txdqKiXvV8EcQlv6hci/LQzeDm5oDlv+BX7hmtiSoHzBaO2/gqKbFPl7MoV/4JuApvVaBWbq' +'ABIDp0BVJSRTRLPGTz+EWRa9ZllhANuGaLmAwq4eJK7eEs4IhwUZYYwFgv0XI5AtLu7q69vQJ54j' +'FmsXvdAeumwL1fk8rKIF9+QgEmcvNtpwdCwL8mdFvCd8y5MmrpaJ9fGXILOfQMyiICTg8Q6g9yBi' +'h45B8x2tD/8tu3NvHH8B9EZlK6ozLtkAAAAASUVORK5CYII=',formatdatetime('yyyyMMddhhmmsszzz".jpg"',now)); if $f<>'' then begin '文件保存成功,文件名为:'$f;' <img src="'$f'">' end else begin '文件保存失败。'; end; ?>
Base64toFile的应用场景,比如手机app端提交一张图片上来,服务端接收并保存成图片,然后返回可访问的路径,比如app中上传自定义人物头像,上传照片等,当然也可以上传其它类型的文件。关于文件上传这块,脚本模型还提供了单独的接口,请参考upfile.html这个演示。