<?php $base64 = file_get_contents("php://input"); //获取输入流 $base64 = json_decode($base64,1); $data = $base64[‘base64‘]; preg_match("/data:image\/(.*);base64,/",$data,$res); $ext = $res[1]; if(!in_array($ext,array("jpg","jpeg","png","gif"))){ echo json_encode(array("error"=>1));die; } $file = time().‘.‘.$ext; $data = preg_replace("/data:image\/(.*);base64,/","",$data); if (file_put_contents($file,base64_decode($data))===false) { echo json_encode(array("error"=>1)); }else{ echo json_encode(array("error"=>0)); }
时间: 2024-10-04 01:35:37