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


Current Path : /var/www/html/studentportal_wait/src/
Upload File :
Current File : /var/www/html/studentportal_wait/src/submitquery.php

<?php
require("database.php");


	$femail = trim($_REQUEST['femail']);
	$fsubject = trim($_REQUEST['fsubject']);
	$fmessage = trim($_REQUEST['fmessage']);
	$file = $_FILES['file'];

	$dir = dirname(__DIR__, 1);
	$tmpfolder = $dir.'/grv Queries/';
	$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
	global $movedFile;
	
	if($file['name']){

		if(!file_exists($tmpfolder))
		{
				mkdir($tmpfolder);
		}
	}else{
		// var_dump($file['name']);
		// echo "else";
	}
	$db = 'logisys3_grv';
	$movedFile = move_uploaded_file($_FILES["file"]["tmp_name"],$tmpfolder.$file['name']);
	// var_dump($movedFile);

	if($_SESSION['MOBILE'] != '')
	{
		$funivcode = $_SESSION['UNIVCODE'];

		$query = "insert into {$db}.grvhead(fgrvdate, fregno, fgrvfrom,fgrvemail,fgrvmobile,fgrvsub,
			fgrvmsg,fgrvuser,fgrvmode,funivcode,fstudemail,fgrvgroup)
			values (now(),'{$_SESSION['REGNO']}','{$_SESSION['SNAME']}','{$_SESSION['EMAIL']}','{$_SESSION['MOBILE']}',
			'{$fsubject}','{$fmessage}','Student','stud. port.','{$funivcode}','{$femail}', '{$_SESSION['HDNO']}')";

		if($conn->query($query) === TRUE)
		{	
			$last_id = $conn->insert_id;
			$res['msg'] = $last_id;
			$res['status'] = "success";
			$res['error_code'] = 0;

			if($movedFile){
				$query = "select fgrvid from {$db}.grvhead where fgrvid= '$last_id'";
				$result = mysqli_query($conn,$query);
				$row = mysqli_fetch_array($result);
	
				$dir = dirname(__DIR__, 2);
				$targetfolder = $dir.'/grv Query Files/';
				if(!file_exists($targetfolder))
				{
						mkdir($targetfolder);
				}
	
				$fname = $funivcode.'_'.$row['fgrvid'].'.'.$ext;
				$targetpath = $targetfolder.$fname;
				$ffilepath = $targetfolder.$targetpath;
				// var_dump($fname);
	
				if(copy($tmpfolder.$file['name'],$targetpath)){	
					
					// echo "renamed and Uploaded";
					$u_query = "update {$db}.grvhead set ffilepath= '{$fname}' where fgrvid= '".$row['fgrvid']."'";
					$result = mysqli_query($conn, $u_query);
					// echo json_encode($res);	
				}else{
					$res['msg'] = 'Not able to Upload file. please try after some time.';
					$res['status'] = "failure";
					$res['error_code'] = -2;
					echo json_encode($res);	
				}	
			}
			else
			{
				// $res['msg'] = 'No files recieved. please try after some time.';
				// $res['status'] = "failure";
				// $res['error_code'] = -2;
				// echo json_encode($res);		
			}
			echo json_encode($res);	

		}

	}
	else
	{
		$res['msg'] = 'Please login to submit the query.';
		$res['status'] = "failure";
		$res['error_code'] = -2;
		echo json_encode($res);
	}