Yii Cmultifileupload Max File Size Validation

I am using CMultifileUpload for the file upload and trying to set the Maximum upload size for the file. As I searched and didn’t get any in-built parameters to set the Max file size before upload.

Here my upload file code,


$filetype="avi|flv|mp4|mpeg|mov|3gp|mkv|vob|divx|mpg|wmv|wlmp";

                $this->widget('CMultiFileUpload', array(

                    'model'=>$model,

                    'name' => 'videofile', 

                    'max'=>1,

                    'accept' => $filetype,  

                    'duplicate' => 'Duplicate file!', 

                    'denied' => 'Invalid file type', 

                    'htmlOptions'=>array('style'=>'opacity: 0;  height: 136px; width: 200px;cursor: pointer;'),

                    'options'=>array(

                        'onFileSelect'=>'function(e, v, m){

    						var size=$("#videofile")[0].files[0].size;

    						alert(size);

    						if(size <=25*1024*1024){

    							$(".black_overlay").show();

    							$("#video-form").submit();

    						}else{

    							alert("File Size Exceeded");

    							$("#video-form").reset();

    							return false;

    						}

                        }',

    					

                     ),

                ));

What i am getting is, the if condition success case is working fine, but for the failure case, the form is not reseting.

And what actually I am trying is, want to validate the file size before submitting.

Help me. Thanks in advance.

You can try this. this will work


'afterFileSelect'=>'function(e ,v ,m){

            var fileSize = e.files[0].size;

                 if(fileSize>800*1024){ <--800KB limit

                    alert("Exceeds file upload limit 800KB");

                    $(".MultiFile-remove").click(); <--cliks the remove button if size exceeds

                  }                      

                  return true;


                }',

This will remove all items, not only the erroneous one

write this instead


$(".MultiFile-remove").last().click()	;