
<?php
include ('session.php');
include('test.php');
include('connection.php');


header( 'Content-Type: text/html; charset=utf8_unicode_ui' );
ini_set('display_errors',1);
error_reporting(E_ALL);
$type = $_POST['type'];
$name=test_input($_POST['name']);
$marathiname=test_input($_POST['marathiname']);
$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.";
  }
 	if ($_FILES["file2"]["size"] > 500000)
 	 {
    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;
						$dest = "pages/images/".$newfilename1;
						file_put_contents($dest1,file_get_contents($src1));
						chmod($dest1, 0777);
	}
$fname1=$dest;
mysqli_query($GLOBALS["___mysqli_ston"], "SET NAMES utf8");
$sql1 = "update collectorimg set status = 'N' where post_type = '$type' and status = 'Y'";
$res1=mysqli_query($GLOBALS["___mysqli_ston"], $sql1) or die("Error message". mysqli_errno($GLOBALS["___mysqli_ston"]));

$sql="INSERT INTO `collectorimg`(name,name_in_marathi,post_type,location) VALUES('$name','$marathiname','$type','$fname1')";
$res=mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die("Error message". mysqli_errno($GLOBALS["___mysqli_ston"]));

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

?>
