<?php


   //getting app id 
   $app_id = $_POST['id'];


//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: gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$app_id."&error=".$errors[1]);
      }
      
      if($file_size > 50000){
         $errors[2]='File size must be exatly 50KB';
		 header("Location: gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$app_id."&error=".$errors[2]);
      }
      
	  
		//prevent overwritten
		$now = date('Y-m-d-His');
	  
      if(empty($errors)==true){
		 $file_name=$user_login_id.'.'.$file_ext;
		 $file_name = $now.$file_name;

       //get applicant pt
      $pty =  get_applicant_programme_type_applied_for($app_id);
      $cid = get_applicant_cart_id($app_id);

      $up_path = '';


      //when Prence
       if( $pty == 1){
         $up_path = '../prence/uploads/';
         //when NCE
       }elseif ($pty == 2) {
            $up_path = '../nce/uploads/';
         if ( $cid == 2) {
              # code...
              $up_path  = '../nce_lvsp/uploads/';
            }else{
                  $up_path  = '../nce/uploads/';
            }
        
       }

         move_uploaded_file($file_tmp, $up_path.$file_name);


        $q = mysql_query("UPDATE applicants_nce SET image='$file_name' WHERE id='$app_id'") ;
		if($q)

		//header('location:dashboard.php?is=image uploaded succesfully');
		 header("Location: gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$app_id."&is=image uploaded succesfully");
		
		
      }
      
   }
   ?>