public function upload($model)
 {
     if ($model->atlas['name'] == "") {
         $model->error->message = "You must specify an atlas file";
         return $this->View($model, "UploadAnimation");
     }
     $atlasFile = $model->atlas['tmp_name'];
     if ($model->texture['name'] == "") {
         $model->error->message = "You must specify a texture file";
         return $this->View($model, "UploadAnimation");
     }
     $textureFile = $model->texture['tmp_name'];
     if ($model->json['name'] == "") {
         $model->error->message = "You must specify a texture file";
         return $this->View($model, "UploadAnimation");
     }
     $jsonFile = $model->json['tmp_name'];
     if ($model->animation == "") {
         $model->error->message = "You must specify an animation name";
         return $this->View($model, "UploadAnimation");
     }
     $animationName = $model->animation;
     $atlasDestName = $animationName . '.atlas';
     $textureDestName = $animationName . '.png';
     $jsonDestName = $animationName . '.json';
     $p = new ImageProcessor($textureFile);
     $p->resizeKeepAspect(50);
     $thumbSource = $p->getFilename();
     $thumbDestName = $animationName . "Thumb.jpg";
     /** @var \com\readysteadyrainbow\entities\Animation $anim */
     $anim = AnimationQuery::create()->findOneByName($animationName);
     if ($anim == null) {
         $anim = new \com\readysteadyrainbow\entities\Animation();
         $anim->setName($animationName);
         $anim->setVersion(1);
         $anim->save();
     } else {
         $anim->setVersion($anim->getVersion() + 1);
         $anim->save();
     }
     global $s3;
     try {
         $s3->putObject(['Bucket' => 'appy-little-eaters', 'Key' => "animations/" . $animationName . "/" . $atlasDestName, 'Body' => fopen($atlasFile, 'r'), 'ACL' => 'public-read']);
         $s3->putObject(['Bucket' => 'appy-little-eaters', 'Key' => "animations/" . $animationName . "/" . $textureDestName, 'Body' => fopen($textureFile, 'r'), 'ACL' => 'public-read']);
         $s3->putObject(['Bucket' => 'appy-little-eaters', 'Key' => "animations/" . $animationName . "/" . $jsonDestName, 'Body' => fopen($jsonFile, 'r'), 'ACL' => 'public-read']);
         $s3->putObject(['Bucket' => 'appy-little-eaters', 'Key' => "animations/" . $animationName . "/" . $thumbDestName, 'Body' => fopen($thumbSource, 'r'), 'ACL' => 'public-read']);
     } catch (S3Exception $e) {
         $model->error->message = $e->getMessage();
         return $this->View($model, "UploadAnimation");
     }
     return $this->RedirectToAction("listAnimations");
 }
Exemple #2
0
 /**
  * @param UploadFoodModel $model
  * @return RedirectToRouteResult|ViewResult
  */
 public function upload($model)
 {
     if ($model->image['name'] == "") {
         $model->error->message = "You must specify an image file";
         return $this->View($model, "UploadFood");
     }
     $imageFile = $model->image['tmp_name'];
     //        if ($model->sound['name'] == "") {
     //            $model->error->message = "You must specify a sound file";
     //            return $this->View($model, "UploadFood");
     //        }
     $soundFile = $model->sound['tmp_name'];
     $soundExt = pathinfo($model->sound['name'], PATHINFO_EXTENSION);
     if ($model->food == "") {
         $model->error->message = "You must specify a food name";
         return $this->View($model, "UploadFood");
     }
     $foodName = $model->food;
     $foodColour = $model->colour;
     $f = FoodQuery::create()->filterByColour($foodColour)->findOneByName($foodName);
     if ($f == null) {
         $f = new \com\readysteadyrainbow\entities\Food();
         $f->setName($foodName);
         $f->setColour($foodColour);
         $f->setVersion(1);
         $f->save();
     } else {
         $f->setVersion($f->getVersion() + 1);
         $f->save();
     }
     $imageDestName = $foodName . ".png";
     $soundDestName = $foodName . "." . $soundExt;
     $p = new ImageProcessor($imageFile);
     $p->resizeKeepAspect(50);
     $thumbSource = $p->getFilename();
     $thumbDestName = $foodName . "Thumb.jpg";
     $p = new ImageProcessor($imageFile);
     $p->resizeKeepAspect(200);
     $mainImageSource = $p->getFilename();
     global $s3;
     if (property_exists($model, 'free') && $model->free == "yes") {
         $base = "freefood/" . $foodColour . "/" . $foodName . "/";
     } else {
         $base = "food/" . $foodColour . "/" . $foodName . "/";
     }
     try {
         $s3->putObject(['Bucket' => 'appy-little-eaters', 'Key' => $base . $imageDestName, 'Body' => fopen($mainImageSource, 'r'), 'ACL' => 'public-read']);
         if ($soundFile != "") {
             $s3->putObject(['Bucket' => 'appy-little-eaters', 'Key' => $base . $soundDestName, 'Body' => fopen($soundFile, 'r'), 'ACL' => 'public-read']);
         }
         $s3->putObject(['Bucket' => 'appy-little-eaters', 'Key' => $base . $thumbDestName, 'Body' => fopen($thumbSource, 'r'), 'ACL' => 'public-read']);
     } catch (S3Exception $e) {
         $model->error->message = $e->getMessage();
         return $this->View($model, "UploadAnimation");
     }
     return $this->RedirectToAction("listFood");
 }