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:
123 |
$base 64_string= explode(, $base 64_string//intercept data:image/png;base64, the comma-after character$ Data= base64_decode ($base 64_string[1]);//use Base64_decode to decode the intercepted charactersfile_put_ Contents($url$data//write to File and save |
PHP Save Base64 Picture base64_decode problem file does not open the question