<?PHPHeader(' Content-type:text/html;charset=utf-8 '); //read image file, convert to Base64 encoding format $image _file= ' Aaa.jpg '; $image _info=getimagesize($image _file); //$base 64_image_content = "data:{$image _info[' mime ']};base64,". Chunk_split (Base64_encode (file_get_contents ($ (image_file) )); $base 64_image_content= "data:{$image _info[' MIME ']}; Base64, ".Base64_encode(file_get_contents($image _file)); //Save the Base64 string as a picture//match the format of the picture if(Preg_match('/^ (data:\s*image\/(\w+); base64,)/',$base 64_image_content,$result)){ $type=$result[2]; $new _file= "./test. {$type}"; if(file_put_contents($new _file,Base64_decode(Str_replace($result[1], ",$base 64_image_content)))){ Echo' New file saved successfully: ',$new _file; } }? >$base 64_image_content;? > "/>
PHP image base64 encoding generated dataurl and saved as a picture