Skip to content

Instantly share code, notes, and snippets.

@realmyst
Forked from kosmatov/image-preview-html5.js
Created August 13, 2012 13:53
Show Gist options
  • Save realmyst/3340984 to your computer and use it in GitHub Desktop.
Save realmyst/3340984 to your computer and use it in GitHub Desktop.
File preview on HTML5/JS/jQuery
$('form').on('change', 'input[type="file"]', function(e) {
var files = e.target.files,
f = files[0],
reader = new FileReader(),
t = this
;
reader.onload = (function(file) {
return function(e) {
$(t).before($('<img>').attr({
src: e.target.result,
title: file.name,
height: "80",
width: ""
}));
};
})(f);
reader.readAsDataURL(f);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment