Last active
May 24, 2017 15:54
-
-
Save pilot/3dfc12dd92028be035580543593a61ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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