0

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;'/>&nbsp;&nbsp;<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;'/>&nbsp;&nbsp;<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;       
        }
    }
}); 
    });
Yes Barry
  • 9,514
  • 5
  • 50
  • 69
Kichu
  • 3,284
  • 15
  • 69
  • 135
  • Possible duplicate of http://stackoverflow.com/questions/307679/using-jquery-restricting-file-size-before-uploading – Rupesh Pawar Dec 10 '11 at 09:21

1 Answers1

0

You can´t. If you want check the file size you have to do this in server side and then return the status of the upload.

josegil
  • 365
  • 1
  • 8