Skip to content

Instantly share code, notes, and snippets.

@edk24
Created August 27, 2019 03:25
Show Gist options
  • Save edk24/a1609b39fdaf4817bf1dfe03020564e8 to your computer and use it in GitHub Desktop.
Save edk24/a1609b39fdaf4817bf1dfe03020564e8 to your computer and use it in GitHub Desktop.
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>files-h5</title>
</head>
<body>
<input type="file" id="file" onchange="showPreview(this, 'portrait')" />
<img src="" id="portrait" style="width: 200px; height: 200px; display: block;" />
<script>
function showPreview(source, imgId) {
var file = source.files[0];
if(window.FileReader) {
var fr = new FileReader();
fr.onloadend = function(e) {
document.getElementById(imgId).src = e.target.result;
}
fr.readAsDataURL(file);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment