Skip to content

Instantly share code, notes, and snippets.

@allenfantasy
Created October 4, 2013 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allenfantasy/6828255 to your computer and use it in GitHub Desktop.
Save allenfantasy/6828255 to your computer and use it in GitHub Desktop.
file preview by javascript. Reaaaaaally rocks!
// html
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
// javascript
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]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment