Skip to content

Instantly share code, notes, and snippets.

@jay16
Created November 21, 2013 07:41
Show Gist options
  • Save jay16/7577452 to your computer and use it in GitHub Desktop.
Save jay16/7577452 to your computer and use it in GitHub Desktop.
preview image on browsesr before upload to sever
Browser: firefox
<img id=“blah” src=“#” /><br> <%= file_field_tag ‘image’, :onchange => “readURL(this)” %>
<script type=“text/javascript”>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
$('#blah').attr('width', "150");
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment