<?php
$target_dir = "image/";

// Allowed types
$type_map = [
    "BR" => "BR",
    "CS" => "CS",
    "Lw" => "Lw",
    "Cs2v2" => "Cs2v2",
    "Ludo" => "Ludo",
    "Free" => "Free"
];

// POST থেকে type
if (!isset($_POST["type"])) die("Error: type required");
$type = $_POST["type"];

// Invalid type check
if (!array_key_exists($type, $type_map)) die("Error: Invalid type");

// সবসময় .png নাম
$new_name = $type_map[$type] . ".png";
$target_file = $target_dir . $new_name;

// ফাইল আপডেট
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
    echo "Success: " . $new_name;
} else {
    echo "Error: Upload failed";
}
?>