/** * Creates a new Category model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Category(); if ($model->load(Yii::$app->request->post())) { $upload = Up::getInstance(); if ($upload) { $upload->on(Up::EVENT_AFTER_UPLOAD, ['backend\\components\\helpers\\Image', 'thumb']); $upload->on(Up::EVENT_AFTER_UPLOAD, ['backend\\components\\helpers\\Image', 'water'], null, false); $upload->save($model, 'cover', 'post'); } if ($model->save()) { return $this->redirect(['index']); } } return $this->render('create', ['model' => $model]); }
/** * @name 图片上传,用于百度的webupload插件 */ public function actionWeb() { $id = \Yii::$app->request->get('id'); \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if (Yii::$app->request->post()) { $res_name = Yii::$app->request->post('res_name'); $upload = Up::getInstanceByName('file', $res_name); $img_config = $upload->getConfig(); $upload->on(Up::EVENT_AFTER_UPLOAD, ['common\\components\\helpers\\Image', 'thumb']); if (isset($img_config['water'])) { //水印 $upload->on(Up::EVENT_AFTER_UPLOAD, ['common\\components\\helpers\\Image', 'water'], null, false); } if (isset($img_config['db'])) { //是否存入数据库 $upload->on(Up::EVENT_AFTER_UPLOAD, ['common\\models\\Attachment', 'db']); } $upload->save(); $info = $upload->getInfo(); return ['status' => 1, 'info' => null, 'data' => ['web_url' => $info['path'] . '/' . $info['fileName'], 'mid' => $info['mid']]]; } }