Esempio n. 1
0
 /**
  * @Route("/myRepoFunctions/filesSubmit/{parent_dir}", name="filesSubmit", defaults={"parent_dir" = null})
  */
 public function filesSubmitAction($parent_dir, Request $request)
 {
     $files = new Files();
     $filesForm = $this->createForm(FilesType::class, $files, ['action' => $parent_dir]);
     $filesForm->add('submit', SubmitType::class, array('label' => 'Upload Files', 'attr' => array('class' => 'btn btn-default pull-right')));
     $em = $this->getDoctrine()->getManager();
     $user = $this->getUser();
     $current_dir = $parent_dir ? $em->getRepository('AppBundle:Directory')->findOneBy(['encodedName' => $parent_dir]) : null;
     $filesForm->handleRequest($request);
     if ($filesForm->isValid()) {
         $filesArray = $files->getFiles();
         foreach ($filesArray as $item) {
             $file = new File();
             $file->setDirectory($current_dir);
             $file->setName($item->getClientOriginalName());
             $em->persist($file);
             $file->uploadFile($item, $user, $current_dir);
         }
         $em->flush();
         return $this->redirectToRoute('dir_show', ['dir_name' => $parent_dir]);
     }
     return false;
 }