<?php
include ('session.php');
include('connection.php');
include('test.php');
header( 'Content-Type: text/html; charset=utf-8' );
$fpath1 = $_SERVER['DOCUMENT_ROOT']."/pdfs/";
$dept_name=test_input($_POST['dept_name']);
$sub=test_input($_POST['sub']);
$disc=test_input($_POST['disc']);
$date=test_input($_POST['dp1']);
//$path1=$_POST['path1'];

$file2= $_FILES['file2']['name'];
$file3= $_FILES['file1']['name'];

if($file2 != '')
{
$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.";
  }*/
 	if ($_FILES["file2"]["size"] > 50000000)
 	 {
    echo "Sorry, your file is too large.";
    $filesize = 1;
  }
   // 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 = substr(microtime(), 2, 7) . '.' .end($temp1);
						$src1 = $_FILES["file2"]["tmp_name"];
						$dest1 = $fpath1.$newfilename1;
						$dest = "pdfs/".$newfilename1;
						file_put_contents($dest1,file_get_contents($src1));
						chmod($dest1, 0777);
   }
$fname1=$dest;
}

if($file3 != '')
{
$imageFileType1 = pathinfo($file3,PATHINFO_EXTENSION);    
$check = getimagesize($_FILES["file1"]["tmp_name"]);  

 if ($_FILES["file1"]["error"] > 0)
  {
			    echo "Error: " . $_FILES["file1"]["error"] . "<br>";
			    $error = 'File Contain Error';
  }
 /*if($check == false) 
  {
       
        echo "File is not an image.";
  }*/
 	if ($_FILES["file1"]["size"] > 50000000)
 	 {
    echo "Sorry, your file is too large.";
    $filesize = 1;
  }
   // Allow certain file formats
if($imageFileType1 != "jpg" && $imageFileType1 != "png" && $imageFileType1 != "jpeg"
&& $imageFileType1 != "pdf" && $imageFileType1 != "PDF" ) 
{
    echo "Sorry, only JPG, JPEG, PNG & pdf files are allowed.";
}
  else
  { 
     
     		$temp1 = explode(".", $_FILES["file1"]["name"]);
						$newfilename1 = substr(microtime(), 2, 7) . '.' .end($temp1);
						$src1 = $_FILES["file1"]["tmp_name"];
						$dest1 = $fpath1.$newfilename1;
						$dest = "pdfs/".$newfilename1;
						file_put_contents($dest1,file_get_contents($src1));
						chmod($dest1, 0777);
   }
$fname2=$dest;
}
$sql="INSERT INTO `success_stories`(`Sr_No`, `dept_name`, `sub`, `description`, `url1`, `photo_path`, `file_path`, `file_flag`, `Sys_Date`, `Status`) VALUES ('','$dept_name','$sub','$disc','$path1','$fname2','$fname1','y',NOW(),'visible')";
//$sql="INSERT INTO `success_stories`(`Sr_No`, `description`, `url1`, `photo_path`, `file_path`, `file_flag`, `Sys_Date`) VALUES ('','$disc','$path1','$fname2','$fname1','y',NOW())";
//echo $sql;

mysqli_query($GLOBALS["___mysqli_ston"], "SET NAMES utf8");
mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die("Error message". mysqli_errno($GLOBALS["___mysqli_ston"]));

echo '<script>
alert("Documents Uploaded..!!!");
window.location.href="success_stories.php"</script>';

		         
?>
