Skip to content

Instantly share code, notes, and snippets.

@volpeo
Created November 26, 2014 11:06
Show Gist options
  • Save volpeo/7b0f8481c408f8a28dbd to your computer and use it in GitHub Desktop.
Save volpeo/7b0f8481c408f8a28dbd to your computer and use it in GitHub Desktop.
Upload button // source http://jsbin.com/gilevurove
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
.fileUpload {
position: relative;
overflow: hidden;
}
.fileUpload input.upload {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
}
.btn {
display: inline-block;
margin-bottom: 0;
font-weight: normal;
text-align: center;
vertical-align: middle;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
white-space: nowrap;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
border-radius: 4px;
color: #333;
background-color: #fff;
border-color: #ccc;
}
</style>
</head>
<body>
<div id="uploadFile"></div>
<div class="fileUpload btn btn-primary">
<span>Upload</span>
<input id="uploadBtn" type="file" class="upload" />
</div>
<script id="jsbin-javascript">
document.getElementById("uploadBtn").onchange = function () {
document.getElementById("uploadFile").innerHTML = this.value.replace(/^.*[\\\/]/, '');
};
</script>
<script id="jsbin-source-css" type="text/css">.fileUpload {
position: relative;
overflow: hidden;
}
.fileUpload input.upload {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
}
.btn {
display: inline-block;
margin-bottom: 0;
font-weight: normal;
text-align: center;
vertical-align: middle;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
white-space: nowrap;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
border-radius: 4px;
color: #333;
background-color: #fff;
border-color: #ccc;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">
document.getElementById("uploadBtn").onchange = function () {
document.getElementById("uploadFile").innerHTML = this.value.replace(/^.*[\\\/]/, '');
};</script></body>
</html>
.fileUpload {
position: relative;
overflow: hidden;
}
.fileUpload input.upload {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
}
.btn {
display: inline-block;
margin-bottom: 0;
font-weight: normal;
text-align: center;
vertical-align: middle;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
white-space: nowrap;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
border-radius: 4px;
color: #333;
background-color: #fff;
border-color: #ccc;
}
document.getElementById("uploadBtn").onchange = function () {
document.getElementById("uploadFile").innerHTML = this.value.replace(/^.*[\\\/]/, '');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment