loveyunk
7/1/2018 - 2:04 AM

upload.html

upload.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #custom-button {
            padding: 10px;
            color: #fff;
            background-color: #009578;
            border: 1px solid #000;
            border-radius: 5px;
            cursor: pointer;
        }

        #custom-button:hover {
            background-color: #00b28f;
        }

        #custom-text {
            margin-left: 10px;
            font-family: sans-serif;
            color: #aaa;
        }
    </style>
</head>
<body>
    
    <input type="file" id="real-file" hidden />
    <button type="button" id="custom-button">CHOOSE A FILE</button>
    <span id="custom-text">No file choose, yet</span>

    <script>
    
        const realFileBtn = document.getElementById('real-file');
        const customBtn = document.getElementById('custom-button');
        const customText = document.getElementById('custom-text');

        customBtn.addEventListener('click', function () {
            realFileBtn.click();
        }, false);

        realFileBtn.addEventListener('change', function () {
            if (realFileBtn.value) {
                customText.innerHTML = realFileBtn.value;
            } else {
                customText.innerHTML = 'No file chosen, yet.';
            }
        }, false);
        

    </script>

</body>
</html>