File: /var/www/selfanalyse/self-strength-test/save_image.php
<?php
// ini_set('dsiplay_errors', 1);
// error_reporting(E_ALL);
// $json = file_get_contents('php://input');
// $data = json_decode($json);
$testId = $_REQUEST['test_id'];
$image_path = $_REQUEST['image'];
$type = $_REQUEST['type'];
$imagename = $_REQUEST['imagename'];
if ($testId != '' && $image_path != '') {
if ($type == 'bar') {
$image_name = $testId .'-'.$imagename. '-bar.png';
$path = '/var/www/selfanalyse/self-strength-test/chart_images/'.$image_name;
if (file_exists($path)) {
echo "exist";
} else {
$url = $image_path;
$img = '/var/www/selfanalyse/self-strength-test/chart_images/' . $image_name;
file_put_contents($img, base64_decode($url));
}
} else if($type == 'circle') {
$image_name = $testId .'-'.$imagename. '-circle.png';
$path = '/var/www/selfanalyse/self-strength-test/chart_images/'.$image_name;
if (file_exists($path)) {
echo "exist";
} else {
$url = $image_path;
$img = '/var/www/selfanalyse/self-strength-test/chart_images/' . $image_name;
file_put_contents($img, base64_decode($url));
}
}
}