Created
July 24, 2015 19:20
-
-
Save chrisgfortes/b4e035274d4b599d0acb to your computer and use it in GitHub Desktop.
Ler imagem e mostrar preview sem upload do arquivo, somente client
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
<img id="preview" src="placeholder.png" height="100px" width="100px" /> | |
<input type="file" name="image" onchange="previewImage(this)" accept="image/*"/> | |
<script type="text/javascript"> | |
function previewImage(input) { | |
var preview = document.getElementById('preview'); | |
if (input.files && input.files[0]) { | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
preview.setAttribute('src', e.target.result); | |
} | |
reader.readAsDataURL(input.files[0]); | |
} else { | |
preview.setAttribute('src', 'placeholder.png'); | |
} | |
} | |
</script> | |
Referência: http://stackoverflow.com/questions/5256620/how-can-i-show-a-image-preview-in-the-browser-without-uploading-the-image-file-t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment