PHP support for Base64 is very good, there is a built-in Base64_encode and Base64_decode responsible for the image of the Base64 encoding and decoding.
On the encoding, as long as the picture stream is read, and then using Base64_encode to encode can be obtained.
And decoding a little bit of trouble, the reason is that the image encoded into a base64 string, the code will be added to these characters data:image/png;base64, originally used for base64 identification. But if you put it directly into PHP with the Base64_decode function decoding will cause the final saved picture file format corruption, and the solution is to first remove this string of characters:
$base 64_string= explode (', ', $base 64_string); Intercept data:image/png;base64, this comma after the character $data= Base64_decode ($base 64_string[1]); Use Base64_decode to decode the intercepted characters file_put_contents ($url, $data); Write Files and save