<?php 
require 'config_db.php';
$data = json_decode(file_get_contents('php://input'), true);
if($data['file_name'] == ''  or $data['mode'] == '')
{
    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");
}
else
{
    $mode = strip_tags(mysqli_real_escape_string($con,$data['mode']));
    $fileName = strip_tags(mysqli_real_escape_string($con,$data['file_name']));
    $img_id = strip_tags(mysqli_real_escape_string($con,$data['img_id']));
    $logo = $data['logo'];
    
    if($mode == 1) {
        if($logo != '' || $logo != null) {
            $image_base64 = base64_decode($logo);
            header('Content-Type: bitmap; charset=utf-8');
            $image_file_name = $fileName. '.png';
            $uploadfile = $file_upload_gallery_url   . "/" . $image_file_name;
            
            $accesspath = $file_upload_gallery_extension_url. "/";
            $savefile = $accesspath . $image_file_name;
    
            file_put_contents($uploadfile, $image_base64);
            
            $update_customer_sql1 = "update app_gallery set `img_url`='$savefile' where id = '$img_id'";
            $result1 = $con->query($update_customer_sql1);
            if($result1) {
                $returnArr = array(
    			"ResponseCode" => "200",
    			"Result" => "true",
    			"ResponseMsg" => "Image Updated Successfully",
    			"logo" => $savefile,
    			"data" => []);
            } else {
                $returnArr = array(
    			"ResponseCode" => "201",
    			"Result" => "false",
    			"ResponseMsg" => "Image Update Failure",
    			"logo" => null,
    			"data" => []);
            }

        } else {
            $returnArr = array(
    			"ResponseCode" => "201",
    			"Result" => "false",
    			"ResponseMsg" => "Image Update Failure",
    			"logo" => null,
    			"data" => []);
        }
    }
   
}
echo json_encode($returnArr);