$maxFileSize) {
$errors[] = $key . " is too large (max 10MB).";
continue;
}
if (!in_array($file['type'], $allowedTypes)) {
$errors[] = $key . " must be JPG, PNG, GIF or PDF.";
continue;
}
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
$safeName = $key . '_' . time() . '_' . uniqid() . '.' . $ext;
$target = $uploadDir . $safeName;
if (move_uploaded_file($file['tmp_name'], $target)) {
$uploadedFiles[$key] = $target;
} else {
$errors[] = "Failed to save " . $key . ".";
}
}
// Optional extra files
if (!empty($_FILES['extra_files']['name'][0])) {
foreach ($_FILES['extra_files']['tmp_name'] as $i => $tmp) {
if ($_FILES['extra_files']['error'][$i] === UPLOAD_ERR_OK) {
$nameExtra = $_FILES['extra_files']['name'][$i];
$ext = pathinfo($nameExtra, PATHINFO_EXTENSION);
$safeExtra = 'extra_' . time() . '_' . $i . '.' . $ext;
$targetExtra = $uploadDir . $safeExtra;
if (move_uploaded_file($tmp, $targetExtra)) {
$uploadedFiles["extra_$i"] = $targetExtra;
}
}
}
}
if (empty($errors)) {
// Here you can:
// 1. Save to database
// 2. Send email with details + file paths
// 3. Create reference number, etc.
$message = "Application received successfully!
We have your details and documents.
Redirecting to payment...";
$success = true;
// You can build a dynamic payment link here, e.g.
// $paymentLink = "https://pay.example.com?ref=" . urlencode($reference) . "&name=" . urlencode($name) . "&amount=3500";
$paymentLink = "https://your-payment-gateway.com/pay"; // ← CHANGE THIS
// Auto-redirect in 4 seconds
header("Refresh: 4; url=" . $paymentLink);
} else {
$message = "Please fix the following errors:
" . implode("
", $errors);
}
}
?>
Redirecting to payment page in a few seconds...
Click here if not redirected