您当前的位置: 首页 > 

暂无认证

  • 2浏览

    0关注

    94646博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

yii2多文件上传功能(yii自带的UploadedFile类(多文件上传)

发布时间:2021-12-26 02:03:31 ,浏览量:2

控制器:

 public $enableCsrfValidation = false; public function actionUpmore(){ $model=new Upmore(); if (Yii::$app->request->isPost) { $file = UploadedFile::getInstances($model, 'file'); if ($file && $model->validate()) { foreach ($file as $fl) { $fl->saveAs(Yii::$app->basePath."/uploads/".iconv("UTF-8", "GB2312//IGNORE", $fl->baseName). '.' . $fl->extension); } return $this->redirect('upmore'); } } return $this->render('upmore', ['model' => $model]); } } 

视图:

 public $file; /**
     * @inheritdoc
     */ public static function tableName() { return 'upmore'; } /**
     * @inheritdoc
     */ public function rules() { return [ [['file'], 'file', 'maxFiles' => 10,'extensions'=>'jpg,png,gif,txt,doc'], ]; } /**
     * @inheritdoc
     */ public function attributeLabels() { return [ 'id' => 'ID', 'path' => 'Path', 'file' => 'File', 'created_at' => 'Created At', ]; } } 

sql: 在这里插入图片描述 先在frontend下新建一个uploads文件夹哈,就可以啦!!!

在这里插入图片描述

关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

0.4436s