我正在尝试使用 eajaxupload 扩展来处理我网站中的文件上传。我完全按照此处的说明进行操作,但遇到了一个问题:每次上传有效文件时都失败(针对无效文件的验证效果很好)。我用谷歌搜索并在这里找到了可能的解决方案,但我没有成功。这是在我的控制器中:
public function actionUpload() {
Yii::import("ext.EAjaxUpload.qqFileUploader");
$folder='upload/';// folder for uploaded files
$allowedExtensions = array("zip","rar","7z");//array("jpg","jpeg","gif","exe","mov" and etc...
$sizeLimit = 5 * 1024 * 1024;// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder);
$return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
$fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
$fileName=$result['filename'];//GETTING FILE NAME
echo $return;// it's array
}
这在我看来:
$this->widget('ext.EAjaxUpload.EAjaxUpload',
array(
'id'=>'uploadFile',
'config'=>array(
'action'=>$this->createUrl('ProjectController/upload'),
'allowedExtensions'=>array("zip","rar","7z"),//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){ alert(fileName); }",
//'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); }"
)
));
如果我在某个地方出错了,请告诉我。