文件上传
-------iew
<?php $this->widget('ext.EAjaxUpload.EAjaxUpload',
array(
'id'=>'uploadFile',
'config'=>array(
'action'=>'/developer/space/upload',
'allowedExtensions'=>array("jpg","jpeg","gif","png"),//array("jpg","jpeg","gif","exe","mov" and etc...
'sizeLimit'=>10*1024*1024,// maximum file size in bytes
'minSizeLimit'=>1*1024,// minimum file size in bytes
'template'=> '<div class="qq-uploader">' .
'<div class="qq-upload-drop-area"><span></span></div>' .
'<div class="qq-upload-button">上传图片</div>' .
'<ul class="qq-upload-list" style="display:none;"></ul>' .
'</div>',
'onProgress' => "js:function(){
$('#loading').remove();
var str='<span id=\'loading\' style=\'position:absolute;left:520px;bottom:290px;\'><img src=\'/style/images/loading.gif\'>正在上传,请等待....</span>';
$('#uploadFile').append(str);
}",
'onComplete'=>"js:function(id, fileName, responseJSON){
var file = responseJSON.file_url+responseJSON.filename;
$('#Space_file').val(file);
$('#img_url').attr('src',file);
if(responseJSON.success){
$('#loading').html('<font color=green>上传成功!</font>');
}else{
$('#loading').html('<font color=red>上传失败!</font>');
}
}",
// '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); }"
)
)); ?>
View 预览
<div id='tips' style="top:10px"></div>
<?php
$widget=$this->beginWidget('ext.quickdlgs.EFancybox',array(
'easing'=>true,
'contentOptions' => array(
'overlayColor' => '#000',
'overlayOpacity' => 0.9,
'transitionIn' => 'elastic',
'transitionOut' => 'elastic',
'speedIn' => 600,
'speedOut' => 200,
),
));
$cdnurl=Yii::app()->params['cdnImgUrl'].$model->img_path;
$widget->content('预览',"<img id='img_url' src=$cdnurl >"); //show content in a fancybox
$this->endWidget();
?>
</div>