<?php 	

require_once '../../Server/connection.php';


$valid['success'] = array('success' => false, 'messages' => array());

$productId = $_POST['productId'];

if($productId) {


$sql55="SELECT * FROM client_docs WHERE  doc_id='$productId'";
		   $query55 = $conn->query($sql55);
		   while($row55 = mysqli_fetch_array($query55)){
                $fileName = $row55['fileName'];
                         }
						 
		$target1 = $fileName;
		$target = '../../files';	
		
		$file = $target."/". $target1;
		
		if (file_exists($file)){
			unlink($file); // delete file  if  exist in the folder
			
			
			
		}


 $sql = "DELETE FROM client_docs WHERE doc_id = {$productId}";
 

 if($conn->query($sql) === TRUE){
 	$valid['success'] = true;
	$valid['messages'] = "Document is successfully Deleted";		
 } else {
 	$valid['success'] = false;
 	$valid['messages'] = "Error while Deleting Document";
 }
			
			
 $conn->close();

 echo json_encode($valid);
 
} // /if $_POST