I have the following code :
<?php
header('Content-Type: image/png');
$data = "iVBORw0KGgoAAAANSUhEUgAAAuAAAAI8CAYAAACwIh5dAAAgAElkZJgRCXxOAuIPzzTlg......";
define('UPLOAD_DIR', '/home/Desktop/image.png');
$img = $data;
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';
?>
Here $data
contain the encoded string of image in base-64. I want to save the image into the file. I did the previous code also go through lot of tutorial in google but it's not working.
Can anyone help me where I am going wrong.
Thanks in advance.