Skip to content

Instantly share code, notes, and snippets.

@loveyunk
Created July 1, 2018 02:04
Show Gist options
  • Save loveyunk/34b6c2f28bb472f219192e310c1d3f1e to your computer and use it in GitHub Desktop.
Save loveyunk/34b6c2f28bb472f219192e310c1d3f1e to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment