$image_file = './164175_100.jpg'; $image_info = getimagesize($image_file); $base64_image_content = "data:{$image_info['mime']};base64," . chunk_split(base64_encode(file_get_contents($image_file))); //然后保存 $upfile = $_POST['upfile'];//编码后的图片 if (preg_match('/^(data:s*image/(w+);base64,)/', $upfile, $result)){ $type = $result[2]; $filename = TIME.'.'.$type; $new_file = ROOT.'temp';//保存的路径 if (!file_put_contents($new_file, base64_decode(str_replace($result[1], '', $upfile)))){ return array('Error'=>1,'Msg'=>'上传图片失败。'); } }