Пример #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Special $special, Requests\SpecialRequest $request)
 {
     $imageModel = ImageUploadFacade::attachmentUpload($request->file('upl'), new Attachment(), 'specials');
     if ($imageModel) {
         $special->attachment()->associate($imageModel);
     }
     $special->fill($request->all());
     $special->save();
     return redirect()->route('admin.special.index');
 }
Пример #2
0
 /**
  * Creates a new Special model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $fileName = 'file';
     $model = new Special();
     if (isset($_FILES[$fileName])) {
         //return var_dump($_POST);
         $imgs = \yii\web\UploadedFile::getInstancesByName($fileName);
         $img = $imgs[0];
         $mysqlName = time() . '_' . $img->name;
         $url = getcwd() . '/src/special/' . $mysqlName;
         $kaboom = explode(".", $img->tempName);
         // Split file name into an array using the dot
         $fileExt = end($kaboom);
         // Now target the last array element to get the file extension
         self::ak_img_resize($img->tempName, $url, 1024, 683, $fileExt);
         chmod($url, 0755);
         $model->photo_url = $mysqlName;
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }