Exemplo n.º 1
0
 protected function createFile(UploadedFile $uploadedFile, ObjectManager $em, $type)
 {
     $file = $this->getDoctrine()->getRepository(File::class)->findOneBy(['type' => $type]);
     if ($file) {
         $file->unlink();
     } else {
         $file = new File();
     }
     $fileName = $uploadedFile->getClientOriginalName();
     $file->setPath("files/uploads/{$fileName}");
     $file->setType($type);
     $file->setCreatedAt(new \DateTime());
     $uploadedFile->move($this->get('kernel')->getRootDir() . '/../web/files/uploads', $fileName);
     $em->persist($file);
 }