
<?php
include ('session.php');
include('connection.php');
include('test.php');
header( 'Content-Type: text/html; charset=utf-8' );
$fpath1 = $_SERVER['DOCUMENT_ROOT']."/pdfs/";  
$srno=test_input($_POST['srno']);
$dept_name=test_input($_POST['dept_name']);
$dept_name1=test_input($_POST['dept_name1']);
$sub_dept_name=test_input($_POST['sub_dept_name']);
$dp1=test_input($_POST['dp1']);
$emp_welf_sub=test_input($_POST['emp_welf_sub']);
$file_text=test_input($_POST['file_text']);
$file2= $_FILES['file2']['name'];

$imageFileType = pathinfo($file2,PATHINFO_EXTENSION);    
$check = getimagesize($_FILES["file2"]["tmp_name"]);  
 if ($_FILES["file2"]["error"] > 0)
  {
			    echo "Error: " . $_FILES["file2"]["error"] . "<br>";
			    $error = 'File Contain Error';
  }
 /*if($check == false) 
  {
       
        echo "File is not an image".$check['mime'].".";
  }*/
 	if ($_FILES["file2"]["size"] > 5000000000)
 	 {
    echo "Sorry, your file is too large.";
  }
   // Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "pdf" && $imageFileType != "PDF" ) 
{
    echo "Sorry, only JPG, JPEG, PNG & pdf files are allowed.";
}
  else
  { 
     
     		$temp1 = explode(".", $_FILES["file2"]["name"]);
						$newfilename1 = round(microtime(true)) . '.' . end($temp1);
						$src1 = $_FILES["file2"]["tmp_name"];
						$dest1 = $fpath1.$newfilename1;
					//echo $dest1;
						$dest = "../pdfs/".$newfilename1;
						file_put_contents($dest1,file_get_contents($src1));
						chmod($dest1, 0777);
   }
$fname1=$dest;
			         
      
		         
mysqli_query($GLOBALS["___mysqli_ston"], "set NAMES utf8");
$sql2="SELECT * from pdf_upload11";

$id=1;
$result11=mysqli_query($GLOBALS["___mysqli_ston"], $sql2) or die('Query Failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
while($row1=mysqli_fetch_assoc($result11))
{		
$ss=$row1['srno'];
$id=$ss+1;
//echo $ss;
}

$sql="INSERT INTO `pdf_upload11`(`srno`, `department_name`, `sub_dep_name`, `sub_of_sub_dept`, `Date`, `document1`, `file_text`, `Status`, `LastModified`) VALUES ('','$dept_name1','$dept_name','$sub_dept_name','$dp1','$fname1','$file_text','Visible',NOw())";


$res=mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die("Error message". mysqli_errno($GLOBALS["___mysqli_ston"]));
echo '<script>
alert("Documents Uploaded..!!!");
window.location.href="pdf_up11.php"</script>';

?>
