Пример #1
0
 /**
  * Creates a new Pictures model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Pictures();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 public function actionUpload()
 {
     $model = new UploadForm();
     $pic = new Pictures();
     echo "1";
     if (Yii::$app->request->isPost) {
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->validate()) {
             $Name = time();
             $url = Yii::$app->basePath . "/web/img/";
             $model->file->saveAs($url . $Name . '.' . $model->file->extension);
             $pic->url = '/img/' . $model->file->baseName . '.' . $model->file->extension;
             $pic->save();
         }
     }
     echo "1";
 }
Пример #3
0
 public function actionUpload()
 {
     $model = new UploadForm();
     $pic = new Pictures();
     $request = YII::$app->request;
     if (Yii::$app->request->isPost) {
         $model->file = UploadedFile::getInstance($model, 'file');
         $name = time();
         //     //$url = Yii::$app->basePath."/web".'/';
         if ($model->validate()) {
             $model->file->saveAs('../../Ontee/web/pictures/' . $name . '.' . $model->file->extension);
             $pic->url = 'pictures/' . $name . '.' . $model->file->extension;
             $pic->name = $model->file->baseName;
             $pic->type = $request->get('type');
             $pic->save();
             return $this->redirect(Url::to(['site/index', 'type' => $pic->type]));
         }
     }
 }