protected function upload(Post $entity) { if (null === $entity->getFile()) { return; } // check if we have an old image if (null !== $entity->getTemp()) { // delete the old image unlink($entity->getTemp()); // clear the temp image path $entity->setTemp(null); } $entity->getFile()->move($entity->getUploadRootDir() . '/' . $entity->getId(), $entity->getImageName() . '.' . $entity->getFile()->guessExtension()); $entity->setFile(null); }