Created
July 28, 2020 19:48
-
-
Save anselmoalima/6f7421a2ebfc06989e24ab49359ea87d to your computer and use it in GitHub Desktop.
Image Preview Before Upload
This file contains hidden or 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
| 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