1

Here is my code:

$img data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2w..........

file_put_contents('myimage.txt',$img);    
file_put_contents('myimage.jpeg', base64_decode($img));


Here is the Output I get:
90KB myimage.txt file
0bytes myimage.jpeg file

I tested the text filehere: Here and it seems to be working. Thanks for the help!

Apache 2.2.23

1 Answers1

3

Well if $img really does contain the 'data:image/jpeg;base64,' data inside it, then base64_decode() will fail because it doesn't contain true base64 data.

$strippedImg = str_replace('data:image/jpeg;base64,','',$img);
file_put_contents('myimage.jpeg', base64_decode($strippedImg));
xxcezz
  • 364
  • 1
  • 7