Upload a file through base64. code
$ Url = "http: // 127.0.0.1/user/update_user_profile.php"; $ post_data = ['User _ id' => '000000', 'sign' => 'weight ', 'category _ type' => '1', 'title' => 'tle1', 'source' => 'source111', 'content' => 'content1111 ', 'image _ list' => 'data: image/png; base64, iVBOElFTkSuQmCC | w * H',]; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // post data curl_setopt ($ ch, CURLOPT_POST, 1); // The variable curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_data); $ output = curl_exec ($ ch); curl_close ($ ch); // Print the obtained data print_r ($ output );
2. process post data submitted by the client
foreach($param_image_list as $param_image_item) { $param_image_data = $param_image_item['image_data']; $param_image_width = $param_image_item['w']; $param_image_height = $param_image_item['h']; $s = base64_decode(str_replace('data:image/png;base64,', '', $param_image_data)); $image_path = '../uploadimg/'.md5($param_user_id).'_'.time().'_'.$index.'.png'; file_put_contents($image_path, $s); $index ++; array_push($image_info_list,$image_path.'|'.$param_image_width.'|'.$param_image_height); }