<p style="text-align: center">
<span style="font-size: 24px; font-family: Simsun; white-space: normal; word-spacing: 0px; text-transform: none; float: none; font-weight: bold; color: rgb(0,0); font-style: normal; orphans: 2; widows: 2; display: inline !important; letter-spacing: normal; text-indent: 0px; font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px"><span class="Apple-converted-space">创建控制器FormController
PHP;">
renderPartial('myfiles',['model'=>$model]);
}
public function actionGetfiles(){
$model = new Uploadm();
if (Yii::$app->request->isPost) {
$model->imgFile = UploadedFile::getInstances($model,'imgFile');
if ($model->upload()) {
// 文件上传成功
echo '上传成功';
}
}
}
创建模型Uploadm.PHP
PHP;">
5],//最多5张
];
}
public function upload()
{
if ($this->validate()) {
foreach ($this->imgFile as $file) {
$file->saveAs('uploads/' . $file->baseName . '.' . $file->extension);
}
return true;
} else {
return false;
}
}
}
创建视图/views/form/myfiles.PHP
PHP;">
'login-form','options' => ['class' => 'form-horizontal','enctype' => 'multipart/form-data'],'action'=>'?r=form/getfiles','method'=>'post'
]) ?>
= $form->field($model,'imgFile[]')->fileInput(['multiple' => true]) ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('上传',['class' => 'btn btn-primary']) ?>