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.218.119.140
<?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);
$user = json_decode($_REQUEST['body'],true);
// var_dump($user);
// die();
$univcode = $user['fcuruniv'];
$fuserid = $user['fuserid'];
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));
$unvi = $arr[0];
$fyear = $arr[1];
$valno = $arr[2];
$barcode = $arr[3];
$ansbook = (explode(".",$arr[4]));
$ansbookno = $ansbook[0];
$qpcode = substr($barcode,0,(strlen($barcode)-6));
$packno = substr(substr($barcode,-6),0,4);
$slno = substr($barcode,-2);
$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);
}
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."/".$filename;
try{
$s3->putObject(['Bucket' => "university-codeslips", 'Key' =>$folder, 'SourceFile' => $file_path]);
$insert_qry = "INSERT INTO codeslips
(funivcode ,fyear ,fexamtype ,fqpcode ,fpacket ,fslno ,fansbook , fregcode, ffilepath,fuploaddate)
VALUES
( '{$unvi}','{$fyear}','{$valno}','{$qpcode}','{$packno}','{$slno}','{$ansbookno}','{$barcode}','{$folder}', now())";
$lobj_rs = $conn_db->query($insert_qry);
unlink($file_path);
} catch(S3Exception $e){
$arr = 'Unable to Upload File';
echo $arr,-1,"failure";
return;
}
}
}
if($lobj_rs)
{
$arr='File Uploaded Successfully';
echo $arr,0,"success";
return;
}
else
{
$arr='File Uploaded Failed';
echo $arr,-1,"failure";
return;
}
}
echo $path;
mysqli_close($conn);
echo $filename;
|