控制器部分
class TblAdminController extends Controller{
public $layout = '//layouts/column';
public function actionIndex(){
$data = array("admin"=>'admin1','password'=>'password1');
$this->render('index',$data);
}
public function actionView(){
if(isset($_FILES['files']) ){
$destination = YiiBase::getPathOfAlias('webroot').'/images/images/';
foreach($_FILES['files']['name'] as $key=>$val ){
move_uploaded_file($_FILES['files']['tmp_name'][$key],$destination.$val);
}
}
$this->render('view');
}
}
视图部分
<div class="form">
<?php $form=$this->beginWidget('CActiveForm',array(
'method' =>'post',
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
));
?>
<?php $this->widget('CMultiFileUpload',array(
'name'=>'files',
'accept'=>'jpg|png',
'max'=>3,
'remove'=>'Remove',
//'denied'=>'', message that is displayed when a file type is not allowed
//'duplicate'=>'', message that is displayed when a file appears twice
'htmlOptions'=>array('size'=>25),
)); ?>
<div class="row submit">
<?php echo CHtml::submitButton('Upload'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Yii文件上传 添加了, 视图实现用widget
最新推荐文章于 2021-03-25 15:46:33 发布