<?php



//file uploads

   if(isset($_FILES['image'])){
      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size =$_FILES['image']['size'];
      $file_tmp =$_FILES['image']['tmp_name'];
      $file_type=$_FILES['image']['type'];
	  
	 
	 
	 
	  
      $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
      
      $expensions= array("jpeg","jpg","png");
      
      if(in_array($file_ext,$expensions)=== false){
         $errors[1]="extension not allowed, please choose a JPEG or PNG file.";
		 header('location:dashboard.php?error='.$errors[1]);
      }
	  
	  
	  
      if($file_size > 50000){
         $errors[2]='File size must be exatly 50KB';
		 header('location:dashboard.php?error='.$errors[2]);
      }
	  
	  
	  
	 
      
      
	  
		//prevent overwritten
		$now = date('Y-m-d-His');
		 $file_name=$user_login_id.'.'.$file_ext;
		 $file_name = $now.$file_name;
		 
		 move_uploaded_file($file_tmp,"../uploads/signature/".$file_name);

		
		
		//get image size by dimension
		   $file_dimension =  getimagesize("../uploads/signature/".$file_name);
		   $width = $file_dimension[0];
		   $height = $file_dimension[1];
		   
		   
		    if($width > 200 )
			{
				   unlink('../uploads/signature/'.$file_name);

				   $errors[3]= 'Image too big, image width must  be 200PX';
				   header('location:dashboard.php?error='.$errors[3]);
			 }
			 
			 
			 if($height > 100)
			 {
				   unlink('../uploads/signature/'.$file_name);

				   $errors[4]= 'Image too big, image height must  be 100PX';
				   header('location:dashboard.php?error='.$errors[4]);

			 }
	  
      if(empty($errors)==true){
		
		 
		  
		 
		 
		 
        $q=mysqli_query(dbc(),"UPDATE students_nce SET sign='$file_name' WHERE id='$user_id'") ;
		if($q)
		header('location:dashboard.php?is=Signature uploaded succesfully');
		
		
		
      }
      
   }
   ?>