1function base64_to_jpeg($base64_string, $output_file) {
2 // open the output file for writing
3 $ifp = fopen( $output_file, 'wb' );
4
5 // split the string on commas
6 // $data[ 0 ] == "data:image/png;base64"
7 // $data[ 1 ] == <actual base64 string>
8 $data = explode( ',', $base64_string );
9
10 // we could add validation here with ensuring count( $data ) > 1
11 fwrite( $ifp, base64_decode( $data[ 1 ] ) );
12
13 // clean up the file resource
14 fclose( $ifp );
15
16 return $output_file;
17}