js code:
$(".head").change(function() {var val = $(this).val();if(!val.match( /.jpg|.gif|.png|.bmp/i ) ){ imgtype = false;alert('Image format is invalid!'); }else{if (FileReader) {var reader = new FileReader(),file = this.files[0];reader.onload = function(e) {var image = new Image();image.src = e.target.result;image.onload=function(){if(image.width > 128 || image.height > 128){fill = false;alert("The avatar size should be between 128x128");} }};reader.readAsDataURL(file);}else{//This is the ie9 version $(".preview_size_fake").show();var objPreviewSizeFake = $(".preview_size_fake").get(0);var fileupload = $(this).get(0);fileupload.select();fileupload.blur();path = document.selection.createRange().text;if (/"/w/W"/.test(path)) {path = path.slice(1,-1);}objPreviewSizeFake.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = path; if(objPreviewSizeFake.offsetWidth > 128 || objPreviewSizeFake.offsetHeight > 128){fill = false;alert("The avatar size should be between 128x128");}document.selection.empty();}}});CSS code (this must be written, if not written, the ie will not work)
.preview_size_fake{ /* This object is only used to obtain the original size of the image under IE, and has no other purpose*/ filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image); height: 1px;visibility:hidden; overflow: hidden; display: none;}html code:
<input type="file" name="avatar"><img />