Created
August 27, 2019 03:25
-
-
Save edk24/a1609b39fdaf4817bf1dfe03020564e8 to your computer and use it in GitHub Desktop.
html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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