<?php
header('Access-Control-Allow-Origin:*');
$imgstr = $_POST['data'];

$filename = uniqid();
$filename = "files/{$filename}.png";

$imgdata = substr($imgstr,strpos($imgstr,",") + 1);
$decodedData = base64_decode($imgdata);
file_put_contents($filename,$decodedData );

echo $filename;
?>