在android手机app上,上传图片,PHP服务端接收图片需要一下步骤
1 需要android 开发人员 把图片转成base64格式
2 PHP端接收转化后的base64字符串,然后进行转译
function saveBase64Img($logo) { $ret = ''; preg_match('/^(data:s*image/(w+);base64,)/', $logo, $result); $type = $result[2]; $year = date('Ymd'); $path = "public/uploads/certity/$year"; if(!is_dir($path)){ mkdir(iconv("UTF-8", "GBK", $path),0777,true); } //sudi_random_code(10) 生成随机字符串的函数 $imgname = sudi_random_code(10).date('ymd'); $new_file =$path.'/'. $imgname . "." . $type; $a =file_put_contents($new_file, base64_decode(str_replace($result[1],'', $logo))); if($a){ return $year.'/'.$imgname . "." . $type; } return $ret; }