decode base64 image php code example
Example 1: php image to base64
$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
Example 2: base64 decode in php
base64_decode('base64');
Example 3: php base64img to file
function base64_to_jpeg($base64_string, $output_file) {
$ifp = fopen( $output_file, 'wb' );
$data = explode( ',', $base64_string );
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
fclose( $ifp );
return $output_file;
}