上传文件 Yii 时添加文件描述 Yii 1.



您好,我正在使用EAjaxUpload扩展程序上传文件,并且它运行良好,并且上传了文件,我想为每个文件添加描述。我使用onComplete来拥有函数,这是我的代码:

$uploadfile = $this->widget('ext.EAjaxUpload.EAjaxUpload',
                        array(
                            'id' => 'uploadFile',
                            'config' => array(
                                'action' => Yii::app()->createUrl('objective/upload'),
                                'allowedExtensions' => array("docx", "pdf", "pptx"),//array("jpg","jpeg","gif","exe","mov" and etc...
                                'sizeLimit' => 5 * 1024 * 1024,// maximum file size in bytes
                                //'minSizeLimit'=>10*1024*1024,// minimum file size in bytes
                                'onComplete' => "js:function(id, fileName, responseJSON){
                                console.log(responseJSON);
                                var filedescription= prompt('file description');
                                  if (filedescription != null) {
                                           document.getElementById('demo').innerHTML =
                                 filedescription;
                                    return filedescription;
                                          }
                                 }",
                                //'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); }"
                            )
                        )); 

现在我想返回 var 文件描述以在控制器中上传操作。我该怎么做?

谢谢

1.onComplete 是在上传请求已通过"目标/上传"操作处理后调用的。因此,您可以在请求之前询问并将描述设置为参数:

'onSubmit' => "js:function(id, fileName){
    // add filedescriton to post parameters:
    this.params.filedescription = 'some file description';
}"

在控制器"目标/上传"操作中,您可以以 $_POST['文件描述'] 的形式访问它。

2.另一种可能性是创建单独的操作来保存描述(和额外的文件处理...),并从onComplete调用它:

在"完成"中:

$.post( 'saveUploadedFileDescription', { filedescription: 'some file description', fileName: fileName } );

在控制器中:

actionSaveUploadedFileDescription($filedescription,$filename) {
    // ....
}

最新更新