This is for saving an image file "PNG", you can also try "JPEG" and other image files.
<?php
$base_url = 'http://www.example.com/';
$file_type = 'image/png';
$file_base = $_POST['dataurl'];
$file_name = "file-".time().".png";
$file_base = str_replace('data:'.$file_type.';base64,', '', $file_base);
$file_base = str_replace('[removed]', '', $file_base);
file_put_contents(getcwd()."/files/$file_name", base64_decode($file_base));
echo $base_url."files/$file_name";
?>
The script below is for saving an application data "PDF" file.
<?php
$base_url = 'http://www.example.com/';
$file_type = 'application/pdf';
$file_base = $_POST['dataurl'];
$file_name = "file-".time().".pdf";
$file_base = str_replace('data:'.$file_type.';base64,', '', $file_base);
$file_base = str_replace('[removed]', '', $file_base);
file_put_contents(getcwd()."/files/$file_name", base64_decode($file_base));
echo $base_url."files/$file_name";
?>
Hope this will help a lot with your development. Happy coding guys!!