Skip to content

Instantly share code, notes, and snippets.

@pilot
Last active May 24, 2017 15:54
Show Gist options
  • Save pilot/3dfc12dd92028be035580543593a61ca to your computer and use it in GitHub Desktop.
Save pilot/3dfc12dd92028be035580543593a61ca to your computer and use it in GitHub Desktop.
<?php
/**
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
* @param \Doctrine\Common\Persistence\ObjectManager $objectManager
* @param PropertyDocument $propertyDocument
* @param boolean $persist
*
* @return array
*/
protected function upload(UploadedFile $file, ObjectManager $objectManager, PropertyDocument $propertyDocument, $persist)
{
if (null === $file) {
return;
}
$user = $this->getCurrentUser();
$webPath = $this->uploadFolder.'/property_document/'.$propertyDocument->getProperty()->getId().'/'.$user->getId().'/';
$dir = $this->uploadRootDir.$webPath;
$filename = sprintf('property_document_%s', uniqid());
$filename = $filename.'.'.$file->guessExtension();
$fs = new Filesystem();
if (!$fs->exists($dir)) {
$fs->mkdir($dir);
}
$file->move($dir, $filename);
$file = [
'name' => $filename,
'path' => $webPath.$filename,
];
return $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment