对于yii xupload扩展

时间:2013-03-16 05:59:40

标签: yii yii-xupload

我想在xupload扩展程序中使用多个属性

我的代码: -

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); }"
                                        ),
            )    
        );

在此我想要每个上传文件exe。可能有所不同,所以我该如何处理它。

1 个答案:

答案 0 :(得分:0)

i got a answer for it:-

我可以上传多种类型的图像,这些图像具有多种接受文件类型和大小:

解决方案: -

在扩展文件夹中找到jquery.fileupload-ui.js: -

然后在此js中添加一个参数。

示例: -   pqueryid:undefined,

        pqueryid1 : undefined,

        lqueryid : undefined,

        lqueryid1 : undefined,

        queryid : undefined,

        queryid1 : undefined,

运行时我需要的所有属性。所以在选项参数中加一个值。

 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();
                            }
                        }
                    );
                });
            }

并在任何需要的地方制作功能。 管理它。