上传文件时添加文件描述 Yii 1
Add a file description when uploading file 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); }"
)
));
现在我想return var filedescription 在控制器中上传动作。我该怎么做?
谢谢,
1.onComplete 在您的上传请求已被 "objective/upload" 操作处理后调用。所以你有可能在请求之前询问并将描述设置为参数:
'onSubmit' => "js:function(id, fileName){
// add filedescriton to post parameters:
this.params.filedescription = 'some file description';
}"
在控制器 "objective/upload" 操作中,您可以通过 $_POST['filedescription'] 访问它。
2.Other 可能性是创建单独的操作来保存描述(和额外的文件处理......)并从 onComplete 调用它:
在完成时:
$.post( 'saveUploadedFileDescription', { filedescription: 'some file description', fileName: fileName } );
在控制器中:
actionSaveUploadedFileDescription($filedescription,$filename) {
// ....
}
您好,我正在使用 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); }"
)
));
现在我想return var filedescription 在控制器中上传动作。我该怎么做?
谢谢,
1.onComplete 在您的上传请求已被 "objective/upload" 操作处理后调用。所以你有可能在请求之前询问并将描述设置为参数:
'onSubmit' => "js:function(id, fileName){
// add filedescriton to post parameters:
this.params.filedescription = 'some file description';
}"
在控制器 "objective/upload" 操作中,您可以通过 $_POST['filedescription'] 访问它。
2.Other 可能性是创建单独的操作来保存描述(和额外的文件处理......)并从 onComplete 调用它:
在完成时:
$.post( 'saveUploadedFileDescription', { filedescription: 'some file description', fileName: fileName } );
在控制器中:
actionSaveUploadedFileDescription($filedescription,$filename) {
// ....
}