File "kyc_process.php"
Full path: /home/quiczmwg/lightspringdigitals.com/../../quiczmwg/wealthspringinc.org/kyc_process.php
File size: 2.83 KiB (2902 bytes)
MIME-type: text/x-php; charset=us-ascii
Charset: utf-8
Download Open Edit Advanced Edit Back
<?php
session_start();
// Check if the user is logged in
if (!isset($_SESSION['userid'])) {
header("Location: login.php");
exit();
}
// Include database connection
include_once("_db.php");
// Fetch user ID from session
$userID = $_SESSION['userid'];
// Retrieve form data
$full_name = $_POST['full_name'];
$email = $_POST['email'];
$country = $_POST['country'];
// Handle file uploads
$proof_of_id = $_FILES['proof_of_id'];
$proof_of_address = $_FILES['proof_of_address'];
// Allowed file types and max size (e.g., 5MB limit)
$allowed_types = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'application/pdf'];
$max_file_size = 5 * 1024 * 1024; // 5MB
$upload_dir = 'uploads/';
function uploadFile($file, $upload_dir, $allowed_types, $max_file_size) {
$file_name = basename($file["name"]);
$target_file = $upload_dir . $file_name;
$file_type = mime_content_type($file["tmp_name"]); // Get the actual MIME type of the file
$file_tmp = $file["tmp_name"];
$file_size = $file["size"];
// Validate file type and size
if (!in_array($file_type, $allowed_types)) {
return "Invalid file type. Allowed types are: JPG, JPEG, PNG, WEBP, PDF.";
}
if ($file_size > $max_file_size) {
return "File size exceeds the maximum limit of 5MB.";
}
// Check if the file already exists
if (file_exists($target_file)) {
return "A file with this name already exists.";
}
// Move the uploaded file to the target directory
if (move_uploaded_file($file_tmp, $target_file)) {
return $file_name; // Return the file name on success
} else {
return "Error uploading file.";
}
}
// Upload the files and handle potential errors
$proof_of_id_name = uploadFile($proof_of_id, $upload_dir, $allowed_types, $max_file_size);
$proof_of_address_name = uploadFile($proof_of_address, $upload_dir, $allowed_types, $max_file_size);
// Check for errors in file uploads
if (!str_contains($proof_of_id_name, "Error") && !str_contains($proof_of_address_name, "Error")) {
// If files were uploaded successfully, insert the KYC details into the database
$query = "INSERT INTO kyc (userid, full_name, email, country, proof_of_id, proof_of_address) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($query);
$stmt->bind_param("ssssss", $userID, $full_name, $email, $country, $proof_of_id_name, $proof_of_address_name);
if ($stmt->execute()) {
$_SESSION['kyc_update_success'] = 'KYC details have been successfully submitted.';
} else {
$_SESSION['kyc_update_error'] = 'Error submitting KYC details.';
}
$stmt->close();
} else {
// If there was an error during file upload, show the error message
$_SESSION['kyc_update_error'] = 'Error uploading files: ' . $proof_of_id_name . ' ' . $proof_of_address_name;
}
$conn->close();
header("Location: kyc.php");
exit();
?>