<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Simple File Uploader - JS XMLHttpRequest</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        form {
            width: 90%;
            max-width: 400px;
        }
        #progressBar {
            width: 0%;
            height: 30px;
            background-color: #4CAF50;
            text-align: center;
            line-height: 30px;
            color: white;
        }
        #barContainer {
            width: 100%;
            background-color: #ddd;
        }
        input, button {
            width: 100%;
            padding: 10px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <form id="uploadForm" enctype="multipart/form-data">
        <input type="file" name="fileToUpload" id="fileToUpload">
        <input type="password" name="password" id="password" placeholder="Enter upload password">
        <button type="button" onclick="uploadFile()">Upload File</button>
    </form>
    <div id="barContainer">
        <div id="progressBar">0%</div>
    </div>
    <div id="status"></div>

    <script>
        function uploadFile() {
            var file = document.getElementById('fileToUpload').files[0];
            var password = document.getElementById('password').value;

            if (!file || !password) {
                alert('Please select a file and enter the password!');
                return;
            }

            var formData = new FormData();
            formData.append('fileToUpload', file);
            formData.append('password', password);

            var xhr = new XMLHttpRequest();
            xhr.open('POST', 'uploader.php', true);

            xhr.upload.onprogress = function(e) {
                if (e.lengthComputable) {
                    var percentComplete = (e.loaded / e.total) * 100;
                    var progressBar = document.getElementById('progressBar');
                    progressBar.style.width = percentComplete + '%';
                    progressBar.textContent = Math.round(percentComplete) + '%';
                }
            };

            xhr.onload = function() {
                if (xhr.status == 200) {
                    document.getElementById('status').innerHTML = xhr.responseText;
                } else {
                    document.getElementById('status').innerHTML = 'Error: Upload failed.';
                }
            };

            xhr.send(formData);
        }
    </script>
</body>
</html>