您好我正在使用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 filedescription以在控制器中上传动作。我怎么能这样做?
谢谢,
答案 0 :(得分:1)
1.onComplete在您的上传请求已被“客观/上传”操作处理后调用。因此,您可以在请求之前询问并将描述设置为参数:
'onSubmit' => "js:function(id, fileName){
// add filedescriton to post parameters:
this.params.filedescription = 'some file description';
}"
在控制器“目标/上传”操作中,您可以将其作为$ _POST ['filedescription']进行访问。
2.其他可能性是创建单独的操作以保存描述(和其他文件处理...)并从onComplete调用它:
在onComplete中:
$.post( 'saveUploadedFileDescription', { filedescription: 'some file description', fileName: fileName } );
在控制器中:
actionSaveUploadedFileDescription($filedescription,$filename) {
// ....
}