/** * @param UploadedFile $file * @return Document */ public function add(UploadedFile $file) { $document = new Document(); $document->setExtension($file->guessExtension())->setMime($file->getMimeType())->setName($file->getClientOriginalName())->setSize($file->getSize()); if (is_null($document->getExtension())) { $document->setExtension($file->getClientOriginalExtension()); } $this->em->persist($document); $this->em->flush(); $file->move($this->directory . '/' . substr($document->getId(), 0, 1), $document->getId() . '.' . $document->getExtension()); return $document; }