
<?php
include ('session.php');
include('test.php');
include('connection.php');
header( 'Content-Type: text/html; charset=utf-8' );
//$filesize = '';
$head=test_input($_POST['head']);
$head1=test_input($_POST['head1']);
$info=test_input($_POST['info']);
$info1=test_input($_POST['info1']);
$dp1=test_input($_POST['dp1']);
$path=test_input($_POST['path']);
$title1=test_input($_POST['title1']);
$title2=test_input($_POST['title2']);

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

if($file2 != '')
{
$imageFileType = pathinfo($file2,PATHINFO_EXTENSION);    
//echo "Image Type is ".$imageFileType;
$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 = round(microtime(true)) . '.' . end($temp1);
						$newfilename1 = substr(microtime(), 2, 7) . '.' .end($temp1);
						$src1 = $_FILES["file2"]["tmp_name"];
						$dest1 = $fpath.$newfilename1;
						//$dest1 ="http://www.zppalghar.in/new-zppalghar/pdfs/".$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["file3"]["tmp_name"]);  

 if ($_FILES["file3"]["error"] > 0)
  {
			    echo "Error: " . $_FILES["file3"]["error"] . "<br>";
			    $error = 'File Contain Error';
  }
 /*if($check == false) 
  {
       
        echo "File is not an image.";
  }*/
 	if ($_FILES["file3"]["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["file3"]["name"]);
						//$newfilename1 = round(microtime(true)) . '.' . end($temp1);
						$newfilename1 = substr(microtime(), 2, 7) . '.' .end($temp1);
						$src1 = $_FILES["file3"]["tmp_name"];
						$dest1 = $fpath.$newfilename1;
						//$dest1 ="http://www.zppalghar.in/new-zppalghar/pdfs/".$newfilename1;
						$dest = "pdfs/".$newfilename1;
						file_put_contents($dest1,file_get_contents($src1));
						chmod($dest1, 0777);
   }
$fname2=$dest;
}
  
	$sql2="SELECT * from currentupdate";
	$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;
		}
if($filesize != 1)
{
			$sql="INSERT INTO `currentupdate`(`srno`, `rank`, `Header`, `Header_marathi`, `News`, `News_marathi`, `Date`, `Photos&videos`, `title1`, `document1`, `title2`, `document2`, `url`, `Status`, `LastModified`) VALUES 
			('','','$head','$head1','$info','$info1','$dp1','','$title1','$fname1','$title2','$fname2','$path','visible',NOW())";
			mysqli_query($GLOBALS["___mysqli_ston"], "SET NAMES utf8");
			$res=mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die("Error message". mysqli_errno($GLOBALS["___mysqli_ston"]));
			
			echo '<script>
			alert("Documents Uploaded..!!!");
			window.location.href="currentupdate.php"</script>';
}
else {
	
	echo '<script>
			alert("Documents not Uploaded..!!!");
			window.location.href="currentupdate.php"</script>';
			
	}


?>
