OK this works fine in chrome, safari and etc.
but it doesn't work in IE8
input
<input accept="image/png,image/gif,image/jpeg" id="user_profile_photo" name="user_profile[photo]" type="file">
javasciprt
$("#user_profile_photo").change(function(){
imageIsDelete = false;
readURL(this);
});
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
if(imageSizeValidationCheck(input.files[0].size)){
$('#myprofile_image').attr('src', e.target.result);
}
}
reader.readAsDataURL(input.files[0]);
}
}
function imageSizeValidationCheck(size){
if(size/1024>200){
alert("Please upload image size lower then 200KB");
$("#user_profile_photo").replaceWith($("#user_profile_photo").clone( true ) );
return false;
}else{
return true;
}
}
I debugged this in IE dev tool, and the problem was
input.files
it doesn't exist in IE8(but it works in chrome)
is there an another way to check image size in here?