public function addFileToPerson(Person $person, $postFile = []) { $em = $this->getEntityManager(); $parts = explode('/', $postFile['type']); $public = 'public/'; $link = 'cache/' . $person->getPersonId() . '.' . end($parts); $path = $public . $link; $data = file_get_contents($postFile['tmp_name']); $resized = $this->resizeImage($data, 300, 300, $path); $file = $person->getFile() ?: new File(); $file->setData($resized)->setMimetype($postFile['type']); $em->persist($file); $person->setFile($file); $em->persist($person); $em->flush(); }