<?php
include("../../db.php");
header("Access-Control-Allow-Origin: * ");


              $abc=$_POST['json'];
             $idata=json_decode($abc,true);

             $id= $idata['id'];
             $image_name=$idata['image_name'];
             $base = $idata['image'];
          
      
          
      
        
       $chkphoto=$db->getVal("select photo from staff where idno='".$id."'");
  
         if($chkphoto!=null) 
         {
     
          unlink("../../media/photo/" . $chkphoto);
         
             
         }
         
            
          if(!isset($myObj)) { $myObj = new stdClass(); }
	
   // Decode Image
  	 if($base!=null){
    	   $binary=base64_decode($base);}
  	  else
    	    {
   	 $binary=null;
   	     }
		 
    header('Content-Type: bitmap; charset=utf-8');
	$file_nm='../../media/photo/'.$image_name;
	

    // Images will be saved under 'uploads/assignment' folder   
	$file = fopen($file_nm, 'wb');
	
    // Create File
	if($binary!=null){
    		$x=fwrite($file, $binary);
		}
	fclose($file);
	
	// upload file end
	
	
 $aryData=array(
	
		 "photo"=>$image_name,
		 
	 );
 	
  		
	$flgUp=$db->updateAry("staff",$aryData,"where idno='$id' ");
	
if(!is_null($flgUp))
	{  
		echo json_encode(array('status' => 1, 'msg'=>'Photo Changed Successfully..!'));    
			
	}else
	{		
	 	echo json_encode(array('status' => 0, 'msg'=>'Unable to change Photo..!'));
	}
	

?>