Ejemplo n.º 1
0
 public function uploadAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $request = $this->getRequest();
     $catalogName = $request->get('catalogName');
     $catalogCategory = $request->get('catalogCategory');
     $creationDate = $request->get('creationDate');
     if (!empty($_FILES)) {
         $tempPath = $_FILES['file']['tmp_name'];
         $userEmail = $this->getUserEmail();
         mkdir('C:\\xampp\\htdocs\\CatalogProject\\companies/' . $userEmail . '\\catalogs/' . $catalogName, null, true);
         $uploadPath = 'C:\\xampp\\htdocs\\CatalogProject\\companies' . DIRECTORY_SEPARATOR . $userEmail . DIRECTORY_SEPARATOR . 'catalogs' . DIRECTORY_SEPARATOR . $catalogName . DIRECTORY_SEPARATOR . $_FILES['file']['name'];
         move_uploaded_file($tempPath, $uploadPath);
         $catalog = new Catalog();
         $catalog->setCatalogName($catalogName);
         $catalog->setCatalogCategory($catalogCategory);
         $catalog->setCreationDate($creationDate);
         $catalog->setCatalogPhoto($_FILES['file']['name']);
         $catalog->setUser($this->getUser());
         $em->persist($catalog);
         $em->flush();
         $answer = array('answer' => 'File transfer completed');
         $json = json_encode($answer);
         echo $json;
     } else {
         echo 'No files';
     }
 }
Ejemplo n.º 2
0
 public function createCatalogAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $request = $this->getRequest();
     $catalogName = $request->get('catalogName');
     $catalogCategory = $request->get('catalogCategory');
     $creationDate = $request->get('creationDate');
     $startDate = $request->get('startDate');
     $endDate = $request->get('endDate');
     $start = substr($startDate, 0, 10);
     $end = substr($endDate, 0, 10);
     /////////////////////////////////////////////
     $filename = $_FILES["file"]["name"];
     $name_extension = explode('.', $filename);
     $imageName = $catalogName . '.' . $name_extension[1];
     ///////////////////////////////////////////
     $catalog = new Catalog();
     $catalog->setCatalogName($catalogName);
     $catalog->setCatalogCategory($catalogCategory);
     $catalog->setCreationDate($creationDate);
     $catalog->setStartDate($start);
     $catalog->setEndDate($end);
     $catalog->setNbLikes(0);
     $catalog->setNbViews(0);
     $catalog->setCatalogPhoto($imageName);
     $catalog->setUser($this->getUser());
     $em->persist($catalog);
     $em->flush();
     $this->uploadCatalogPicture($catalogName, $imageName);
     return new JsonResponse($catalog, 200);
 }