Skip to content

Instantly share code, notes, and snippets.

@bogvsdev
Created April 19, 2016 13:57
Show Gist options
  • Save bogvsdev/ad1a986b5cfc84d27f1d716787092273 to your computer and use it in GitHub Desktop.
Save bogvsdev/ad1a986b5cfc84d27f1d716787092273 to your computer and use it in GitHub Desktop.
$('[name="image"]').on('change',function(evt){
if (!window.File && !window.FileReader && !window.FileList && !window.Blob)
return false;
var file = evt.target.files[0]; // FileList object
// Only process image files.
if (!file.type.match('image.*')) {
return;
}
var reader = new FileReader();
// Read in the image file as a data URL.
reader.readAsDataURL(file);
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
$('.preview').attr('src', e.target.result);
};
})(file);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment