-2

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?

Kunj
  • 1,980
  • 2
  • 22
  • 34
Canna
  • 3,614
  • 5
  • 28
  • 33

1 Answers1

4

FileReader is a feature of HTML5 File API, which is supported in IE from 10th version:

http://caniuse.com/filereader

  • Any alternative solution for this? – Canna Dec 30 '13 at 09:29
  • @Canna : have you checked this thread => http://stackoverflow.com/questions/5570871/html5-filereader-alternative – NoobEditor Dec 30 '13 at 09:30
  • @Canna You can use HTML4 with chunks to immitate fileuploader with the progress bar/multiupload. But for HTML4 you must also use ` –  Dec 30 '13 at 09:33