Skip to content

Instantly share code, notes, and snippets.

@hayskytech
Created April 13, 2023 06:35
Show Gist options
  • Save hayskytech/f96a944d6db05c05b79d5715b87f3d53 to your computer and use it in GitHub Desktop.
Save hayskytech/f96a944d6db05c05b79d5715b87f3d53 to your computer and use it in GitHub Desktop.
<input type="file" id="imageUpload" onchange="previewImage()">
<div id="imagePreview"></div>
<script type="text/javascript">
function previewImage() {
var preview = document.getElementById('imagePreview');
img = document.getElementById('imageUpload').files[0];
var reader = new FileReader();
if (img) {
reader.readAsDataURL(img);
} else {
// preview.innerHTML = "";
}
reader.onloadend = function(){
preview.innerHTML = reader.result;
}
}
</script>
<style type="text/css">
#imagePreview{
width: 400px;
height: 200px;
overflow: auto;
word-break: break-all;
border: 1px solid;
padding: 5px;
margin: 5px 0px;
font-family: Arial;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment