
<?php
include('connection.php');
include('test.php');
header( 'Content-Type: text/html; charset=utf-8' );
$title=test_input($_POST['title']);
$title1=test_input($_POST['title1']);
$dp1=test_input($_POST['dp1']);
$file1=test_input($_POST['file2']);

$imageFileType = pathinfo($file1,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"] > 5000000000000)
 	 {
    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
  { 
     
     		$temp = explode(".", $_FILES["file2"]["name"]);
						$newfilename = round(microtime(true)) . '.' . end($temp);
						$src = $_FILES["file2"]["tmp_name"];
						$dest1 = $fpath.$newfilename;
						//$dest1 ="http://www.zppalghar.in/new-zppalghar/pdfs/".$newfilename1;
							$dest = "../pdfs/".$newfilename;
						file_put_contents($dest1,file_get_contents($src));
						chmod($dest1, 0777);
   }
$filename=$dest;

/* $dest2 = '';	         

if ($_FILES["file2"]["error"] > 0)
 {
                echo "Error: " . $_FILES["file2"]["error"] . "<br>";
                $error = 'File Contain Error';
 }
  else
  {
                        $temp1 = explode(".", $_FILES["file2"]["name"]);
                        $filename1 = round(microtime(true)) . '.' . end($temp1);
                        $src1 = $_FILES["file2"]["tmp_name"];
                        $dest1 ="/var/www/prasad/zppalghar/pdfs/".$filename1;
                        $dest = "../pdfs/".$filename1;
                        file_put_contents($dest1,file_get_contents($src1));
                        chmod($dest1, 0777);
   }
$fname1=$dest;			*/         
			         	         
$sql2="SELECT * from publication";
//echo $sql2;
$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 `publication` (`title`, `title1`, `user_date`,`file_path`, `file_flag`, `sys_date`) VALUES ('$title','$title1','$dp1','$filename','Y',NOW())";	

//echo $sql;
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="publication.php"</script>';

?>
