<?php
    session_start();
    include "../../db.php";
    date_default_timezone_set('Asia/Kolkata');
     $currentTime = date('jS  F Y');
    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) )
        header("Location: logout.php");
?>

<?php


if (isset($_POST['image'])) {

    // image upload
    $data = $_POST["image"];
    $image_array_1 = explode(";", $data);
    $image_array_2 = explode(",", $image_array_1[1]);
    $data = base64_decode($image_array_2[1]);
    $imageName = '../upload/blog/thumb/'.rand() . '.jpg';
    file_put_contents($imageName, $data);

    // User Input
    $refid = $_POST['refid'];

    $ins_sql = "UPDATE data_table SET image_thumbnail = '$imageName' WHERE refid = '$refid' ";
    mysqli_query($con, $ins_sql) ;
    if (mysqli_query($con, $ins_sql)) {
        if(!empty($_POST["previousThumbnail"])){
            unlink($_POST["previousThumbnail"]);
        }
        
    }
}


?>