<?php
include("connect.php");
if(isset($_POST['submit']))
{ 
  $allowedExts = array("gif", "jpeg", "jpg", "png","JPG");

// explode the file name to to check the ext
$temp = explode(".", $_FILES["file"]["name"]);

// not sure what end does
$extension = end($temp);

// check file type
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2097152)  // limit the size of the file to 2mb
&& in_array($extension, $allowedExts)){

  // check if there was an error
  if($_FILES["file"]["error"] > 0){
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
  } else {
    // echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    // echo "Type: " . $_FILES["file"]["type"] . "<br>";
    // echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    // echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    // get the date
    // added this to always refrence America/Los_Angeles VS sever timestamp
    $date = new DateTime(null, new DateTimeZone('America/Los_Angeles'));
    $current_date = $date->getTimestamp();
    // add the date to the filename 
    $file_name = $temp[0] . $current_date;
    // add the extension back on. 
    $file = $file_name.".".$temp[1];
    // move the file to its new location
    move_uploaded_file( $_FILES["file"]["tmp_name"], "SW/prof/" .$file);
      
     
     echo '<img src="SW/prof/'.$file.'">';
     echo $file;
  }
} else {
  echo "You have uploaded an invalid file.";
}


    /*
	$name=$_POST['fn'];
	$gender=$_POST['gender'];
	$dob=$_POST['dat'];
	$age=$_POST['age'];
	$address=$_POST['addr'];
	$state=$_POST['stat'];
	$dist=$_POST['dist'];
	$panchayath=$_POST['panch'];
	$pincode=$_POST['pin'];
    $phone=$_POST['phn'];
	$email=$_POST['mail'];
	$ref=$_POST['ref'];
	$bankname=$_POST['bname'];
	$accnumber=$_POST['acnum'];
	$deposit=$_POST['depoamount'];
	$ifsc=$_POST['ifsc'];
	$aadhar=$_POST['aadh'];
	$pan=$_POST['pan'];
	$otp=$_POST['otp'];
	
	
			$check=mysqli_query($con,"select * from otp where otp='$otp' && phone='$phone'");
		if($row=mysqli_fetch_array($check))
		{
		    
		        	$q="insert into list(name,gender,dob,age,reference,address,state,district,panchayat,pincode,status,phone,date,amount,aadhar) values ('$name','$gender','$dob','$age','$ref','$address','$state','$dist','$panchayath','$pincode','0','$phone',(select now()),'$deposit','$aadhar')";
	
                
                	//$q="INSERT INTO list(name,gender,dob,age,fname,address,state,district,panchayath,pincode,phone,email,status)VALUES('$name','$gender','$dob','$age','$fname','$address','$state','$dist','$panchayath','$pincode','$phone','$email','1')";
                	$exe=mysqli_query($con,$q);
                	$x=mysqli_insert_id($con);
                
                	$query1="INSERT INTO bank(bname,bankname,accnumber,depoamount,ifsc,aadhar,pan,lid) VALUES ('$name','$bankname','$accnumber','$deposit','$ifsc','$aadhar','$pan','$x')";
                	$exe1=mysqli_query($con,$query1);
                	$a=mysqli_query($con,"Select * from list");
                	//$exee=mysqli_query($con,"INSERT INTO login(name,lid,username,password,type,depoamount)VALUES('$name','$x','$name','$name','SW','$deposit')");
                	
                	//$exe2=mysqli_query($con,$exee);



            	$filepath = "photo/" .basename( $_FILES["image"]["name"]);
            	$image=$_FILES["image"]["name"];
            		
            		//$x=mysqli_insert_id($con);
            	$queryy="insert into photos(filename,lid)values('$filepath','$x')";
                        	mysqli_query($con,$queryy);
            	if(move_uploaded_file($_FILES['image']['tmp_name'], $filepath)) 
            	{
                		echo "Registraton  sucessfull";
                } 

           
        
            echo "<script>alert('Data added Sucessfully')</script>";  
             echo"<script>window.location.href='index.html';</script>";
            
         }
         
		 */   

    
}





?>