0
<?php 
   $arr = ['data:image/jpeg;base64,/9j/4AAQSkZJR....',
   '....','....','..pPKf56CT/9k=',
   ];

   $arrSize=sizeof($arr);

   for ($i=0;$i<$arrSize;$i++){
      echo $i;
      $data = base64_decode($arr[$i]);
      //echo "  ".$data."</br>";
      file_put_contents('image.png', $data,FILE_APPEND | LOCK_EX);
   }
?>

I cannot open the image that is created, and the file size that is created is nearly 1mb. I created a txt file that opens fine with the decoded data.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Lohit
  • 21
  • 5

1 Answers1

0

note that the first item in the array need a bit of cleanup (removing all that 'date:images...'). also, it is best to 'glue' the encoded string before decoding it. here is the code that will do the trick:

$filename='image.png';
$arrSize=count($arr);
$data=substr($arr[0],strpos($arr[0],',')+1);
for($i=1;$i<$arrSize;$i++) $data.=$arr[$i];
file_put_contents($filename,base64_decode($data));
Shai Shprung
  • 146
  • 8