$('.upload-photo input[type="file"]').change(function(event) {
event.preventDefault();
var files = !!this.files ? this.files : [];
if ( !files.length || !window.FileReader ) return;
if ( /^image/.test( files[0].type ) ) {
var reader = new FileReader();
reader.readAsDataURL( files[0] );
reader.onloadend = function(){
$('.upload-photo .img').css("background-image", "url(" + this.result + ")");
}
}
});
$('input[type="file"]').on('change', function(){
var imgfile = this.files[0];
if (!imgfile.type.match(/image.*/)){
console.error("The selected file is not an image: ", imgfile.type);
return;
}
var reader = new FileReader();
reader.onload = function(e, target){
var img = $('img.your-image');
img.attr('src', e.target.result);
};
reader.readAsDataURL(imgfile);
});