예제 #1
0
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), ProductImage::$rules);
     if ($validator->passes()) {
         $images = Input::file('images');
         $file_count = count($images);
         $uploadcount = 0;
         foreach ($images as $image) {
             if ($image) {
                 $product_image = new ProductImage();
                 $product_image->product_id = Input::get('product_id');
                 $product_image->title = $image->getClientOriginalName();
                 $filename = date('Y-m-d-H:i:s') . "-" . $product_image->title;
                 $path = public_path('img/products/' . $filename);
                 $path_thumb = public_path('img/products/thumb/' . $filename);
                 Image::make($image->getRealPath())->resize(640, 480)->save($path);
                 Image::make($image->getRealPath())->resize(177, 177)->save($path_thumb);
                 $product_image->url = $filename;
                 $product_image->save();
                 $uploadcount++;
             }
         }
         if ($uploadcount == $file_count) {
             return Redirect::back();
         } else {
             return Redirect::back()->with('message', 'Ошибка загрузки фотографии');
         }
     }
     return Redirect::to('admin/products/index')->with('message', 'Ошибка сохранения')->withErrors($validator)->withInput();
 }
예제 #2
0
 /**
  * Creates a new ProductImage model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ProductImage();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }