首先App端把上传的图片使用base64进行编码,然后传给后台PHP处理,再进行base64解码,然后再利用file_put_contents这个函数把它写入到文件夹里面即可,代码如下:
$portrait = I('post.portrait');
if (empty($portrait)) {
returnApi('10001','参数错误');
}
$portrait = base64_decode($portrait);
$time =time();
$fileurl = C('UPLOAD_IMG_ROOTPATH');
$filename = $fileurl.'Portrait/'.$time.'.jpg';
$res= file_put_contents($filename, $portrait);
if (!$res) {
returnApi('10003','上传失败');
}