/** * Creates a new Basic model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $params = Yii::$app->request->post(); if ($params && $params['Basic']) { foreach ($params['Basic'] as $key => $value) { $params['Basic']['update_time'] = time(); $params['Basic']['create_time'] = time(); } #upload qiniu $storage = new QiNiuStorage(); $ret = $storage->upload($params['Basic']['images']); if (isset($ret['url'])) { $params['Basic']['images'] = $ret['url']; } else { throw new ServerErrorHttpException('Upload Qiniu fail,please try again.'); } } $model = new Basic(); if ($model->load($params) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function uploadImg($url) { $storage = new QiNiuStorage(); $ret = $storage->upload($url); return $ret; }