<?php 	
session_start();
require_once '../../Server/connection.php';
include('../includes/session.php');
if($_POST){
  $file_id = $_POST['file_id'];
  $role = 'DCO';
  $sql9 = "SELECT * FROM client_files WHERE file_id='$file_id'";
	$result9 = $conn->query($sql9);
	while($edge9=mysqli_fetch_array($result9)){
	   $clientId = $edge9['client_id'];
	         }
 
	
	if(!empty($_FILES['file']['name'])){
	foreach ($_FILES['file']['name'] as $key => $name){
		$newFilename = time() . "_" . $name;
		move_uploaded_file($_FILES['file']['tmp_name'][$key],'../../files/'.$newFilename);
		$location = '../../files/' . $newFilename;
		
		mysqli_query($conn,"insert into client_docs (client_id,file_id,role,fileName) values ('$clientId','$file_id','$role','$location')");
		
	          }
	          }
			  
			  
   
	$_SESSION['success_message'] = "File Has Been Uploaded Successfully";
                        header("Location: ../addFiles.php?i=$file_id");
                             exit();
     
	
}