我需要在xupload yii扩展名中复制上传文件

时间:2013-01-17 08:52:10

标签: php yii yii-extensions yii-xupload

我有这个xupload文件扩展名:

<?php
        $this->widget( 'xupload.XUpload', array(
            'url' => Yii::app( )->createUrl( "/controller/upload"),
            'model' => $model,
            'htmlOptions' => array('id'=>'somemodel-form'),
            'attribute' => 'file1',
            'multiple' => true,
            'formView' => 'application.views.somemodel.form1',
            'uploadView' => 'application.views.somemodel.upload1',
            'downloadView' => 'application.views.somemodel.download1',
            'options' => array(//Additional javascript options
                //This is the submit callback that will gather
                //the additional data  corresponding to the current file
                'submit' => "js:function (e, data) {
                    var inputs = data.context.find(':input');
                    data.formData = inputs.serializeArray();
                    return true;
                }"
            ),
            )    
        );
        ?>

我需要添加另一个上传文件,但是当我复制这样的代码时:

<?php
        $this->widget( 'xupload.XUpload', array(
            'url' => Yii::app( )->createUrl( "/controller/upload"),
            'model' => $model,
            'htmlOptions' => array('id'=>'somemodel-form'),
            'attribute' => 'file2',
            'multiple' => true,
            'formView' => 'application.views.somemodel.form2',
            'uploadView' => 'application.views.somemodel.upload2',
            'downloadView' => 'application.views.somemodel.download2',
            'options' => array(//Additional javascript options
                //This is the submit callback that will gather
                //the additional data  corresponding to the current file
                'submit' => "js:function (e, data) {
                    var inputs = data.context.find(':input');
                    data.formData = inputs.serializeArray();
                    return true;
                }"
            ),
            )    
        );
        ?>

问题是,当我上传两个上传文件的图像时,它在相同的上传模板上工作,我尝试添加uploadTemplate,下载模板选项但它没有用,请告诉我如何使用uploadTemplate,downloadTemplate以及如何渲染为renderPartial和哪个文件我渲染它,我应该更改此行中的id&lt; script id =“template-upload”type =“text / x-tmpl”&gt;和&lt; script id =“template-download”type =“text / x-tmpl”&gt; upload.php和download.php模板文件,请告诉我该怎么做?

非常感谢

1 个答案:

答案 0 :(得分:2)

我从未在同一页面中使用过多个小部件的XUpload,但试试这个:

对于每个表单模板(application.views.somemodel.form1application.views.somemodel.form2),添加一个类,即。 '文件上传':

//application.views.somemodel.form1
<form class="fileupload" action="server/php/" method="POST" enctype="multipart/form-data">
    <!-- ... -->
</form>

//application.views.somemodel.form2
<form class="fileupload" action="server/php/" method="POST" enctype="multipart/form-data">
    <!-- ... -->
</form>

为每个uploadViewdownloadView创建不同的ID,即:

//application.views.somemodel.upload1
< script id="template-upload1" type="text/x-tmpl">
//application.views.somemodel.download1
< script id="template-download1" type="text/x-tmpl">

//application.views.somemodel.upload2
< script id="template-upload2" type="text/x-tmpl">
//application.views.somemodel.download2
< script id="template-download2" type="text/x-tmpl">

按如下方式配置小部件:

<?php
        $this->widget( 'xupload.XUpload', array(
            'url' => Yii::app( )->createUrl( "/controller/upload"),
            'model' => $model,
            'htmlOptions' => array('id'=>'somemodel-form'),
            'attribute' => 'file1',
            'multiple' => true,
            'formView' => 'application.views.somemodel.form1',
            'uploadView' => 'application.views.somemodel.upload1',
            'downloadView' => 'application.views.somemodel.download1',
            'uploadTemplate' => '#template-upload1', // IMPORTANT!
            'downloadTemplate' => '#template-download1',// IMPORTANT!
            'options' => array(//Additional javascript options
                //This is the submit callback that will gather
                //the additional data  corresponding to the current file
                'submit' => "js:function (e, data) {
                    var inputs = data.context.find(':input');
                    data.formData = inputs.serializeArray();
                    return true;
                }"
            ),
            )    
        );
        ?>

<?php
        $this->widget( 'xupload.XUpload', array(
            'url' => Yii::app( )->createUrl( "/controller/upload"),
            'model' => $model,
            'htmlOptions' => array('id'=>'somemodel-form'),
            'attribute' => 'file2',
            'multiple' => true,
            'formView' => 'application.views.somemodel.form2',
            'uploadView' => 'application.views.somemodel.upload2',
            'downloadView' => 'application.views.somemodel.download2',
            'uploadTemplate' => '#template-upload2', // IMPORTANT!
            'downloadTemplate' => '#template-download2',// IMPORTANT!
            'options' => array(//Additional javascript options
                //This is the submit callback that will gather
                //the additional data  corresponding to the current file
                'submit' => "js:function (e, data) {
                    var inputs = data.context.find(':input');
                    data.formData = inputs.serializeArray();
                    return true;
                }"
            ),
            )    
        );
        ?>