This is my ajax image uploade code.Here i want also check size of the image.If size greater than 1mb display error message as "the size is very large ".How can i do this?
$(function(){
var btnUpload=$('#upload_file');
new AjaxUpload(btnUpload, {
action: '<?php echo site_url('Admin/attachsave');?>',
name: 'file',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif|JPG|PNG|JPEG|GIF)$/.test(ext))) {
// extension is not allowed
// $("#alert").html('Only JPG, JPEG, PNG, GIF are allowed');
$("#alert").show();
$("#alert").html("<img src='<?php echo base_url();?>images/exclamationR.png' style='float:left;'/> <div style='float:left;margin-top:8px;'>Only JPG, JPEG, PNG, GIF are allowed</div>");
$("#alert").css("background-color","#a90b05");
$("#alert").css("padding","0px");
$("#txtimage").css("border","2px solid #f9612c");
$("#txtimage").css("border-radius","5px");
return false;
}
},
onComplete: function(file, response){
if (response) {
//$("#txtimage").val(response);
$("#hd_txtimage").val(response);
add_image();
} else {
$("#alert").show();
$("#alert").html("<img src='<?php echo base_url();?>images/exclamationR.png' style='float:left;'/> <div style='float:left;margin-top:8px;'>Image Size Maximum Is 1Mb</div>");
$("#alert").css("background-color","#a90b05");
$("#alert").css("padding","0px");
$("#txtimage").css("border","2px solid #f9612c");
$("#txtimage").css("border-radius","5px");
return false;
}
}
});
});