Skip to content

Instantly share code, notes, and snippets.

@anselmoalima
Created July 28, 2020 19:48
Show Gist options
  • Select an option

  • Save anselmoalima/6f7421a2ebfc06989e24ab49359ea87d to your computer and use it in GitHub Desktop.

Select an option

Save anselmoalima/6f7421a2ebfc06989e24ab49359ea87d to your computer and use it in GitHub Desktop.
Image Preview Before Upload
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]); // convert to base64 string
}
}
$("#imgInp").change(function() {
readURL(this);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment