Search code examples
yiiyii-xupload

for yii xupload extensition


i wants to using a multiple attribute in xupload extension

my code :-

Yii::import("xupload.models.XUploadForm"); 

  $this->widget( 'xupload.XUpload', array(
            'id'=>'uploadwidget',
            'url' => Yii::app( )->createUrl("$mo"),
            'model' => $photo,
            'htmlOptions' => array('id'=>'testmagazines-form'),
            'attribute' => 'file',
            'multiple' => true,
            'options'=>array(
                              'maxNumberOfFiles'=>3,
                              'maxFileSize'=>"js:$('#filesize').val()",
                              'acceptFileTypes'=>"js:/(\.|\/)(jpeg)$/i",

                              'completed' =>"js:function(id, fileName, responseJSON){
                                var value = $('#number').val();
                                var value1 =  parseInt(value) + parseInt(1);
                                $('#number').val(value1);       
                                jQuery(document).trigger('close.facebox');
                                }",
                                'success'=>"js:function(res){ 
                                 var b = $('#number').val();
                                if(b=='1'){ 
                                $('#filesize').val('104857600');

                                }else if(b=='2'){
                                $('#filesize').val('104857600');
                                }else if (b==3){
                                $('#filesize').val('10*1024*1024');
                                }
                                    alert(res[0].mode);
                                }",
                              'messages'=>array(
                                        'typeError'=>"{file} has invalid extension. Only {extensions} are allowed.",
                                        'sizeError'=>"{file} is too large, maximum file size is {sizeLimit}.",
                                        'minSizeError'=>"{file} is too small, minimum file size is {minSizeLimit}.",
                                        'emptyError'=>"{file} is empty, please select files again without it.",
                                        'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
                                                ),
                                        'showMessage'=>"js:function(message){ alert(message); }"
                                        ),
            )    
        );

in this i want to every upload file exe. may be difference so i how to handle it.


Solution

  • i got a answer for it:-
    

    i can upload a multiple types of images with multiple accept file type and also size:

    Solution:-

    in find a jquery.fileupload-ui.js in a extension folder:-

    then add a parameter in this js.

    example :- pqueryid : undefined,

            pqueryid1 : undefined,
    
            lqueryid : undefined,
    
            lqueryid1 : undefined,
    
            queryid : undefined,
    
            queryid1 : undefined,
    

    all Attribute i need at run time . so put a value in option parameters.

     add: function (e, data) {
                    var that = $(this).data('fileupload'),
                        options = that.options,
                        files = data.files;
    
                    $(this).fileupload('process', data).done(function () {
                        that._adjustMaxNumberOfFiles(-files.length);
    
                 if(counter==2)
                    {
                    var dataurl ='/project/client/magazinecms/admin/index.php?r=testMagazines/uploadnew&imagename=dev_cert_path&id='+that.options.queryid1+'&queryid='+that.options.queryid+'&m=testMagazines' 
                    that.options.url = dataurl;
                    that.options.acceptFileTypes =/(\.|\/)(pem)$/i;
                    counter--;
                     }else if(counter==1)
                    {
                    var dataurl ='/project/client/magazinecms/admin/index.php?r=testMagazines/uploadnew&imagename=prod_cert_path&id='+that.options.pqueryid1+'&queryid='+that.options.pqueryid+'&m=testMagazines'
                    that.options.url = dataurl;
                    that.options.acceptFileTypes =/(\.|\/)(pem)$/i;
                    counter--;
                    }else{
                    var dataurl ='/project/client/magazinecms/admin/index.php?r=testMagazines/uploadnew&imagename=logo_path&id='+that.options.lqueryid1+'&queryid='+that.options.lqueryid+'&m=testMagazines'
                    that.options.url = dataurl;
                    that.options.acceptFileTypes =/(\.|\/)(jpeg|jpg|png)$/i;
                    counter--;
                    }
    
                        data.isAdjusted = true;
                        data.files.valid = data.isValidated = that._validate(files);
                        data.context = that._renderUpload(files).data('data', data);
                        options.filesContainer[
                            options.prependFiles ? 'prepend' : 'append'
                        ](data.context);
                        that._renderPreviews(files, data.context);
                        that._forceReflow(data.context);
                        that._transition(data.context).done(
                            function () {
                                if ((that._trigger('added', e, data) !== false) &&
                                        (options.autoUpload || data.autoUpload) &&
                                        data.autoUpload !== false && data.isValidated) {
                                    data.submit();
                                }
                            }
                        );
                    });
                }
    

    and making a function any where need. manage it.