Example #1
0
 public function load(ObjectManager $manager)
 {
     foreach ($this->data as $fileData) {
         $file = new File();
         $file->setDirectory($this->getReference($fileData['directory_reference']));
         $file->setName($fileData['name']);
         $file->setParams(new UploadedFileParametersModel());
         $file->setPath($fileData['path']);
         $manager->persist($file);
         $this->addReference($fileData['file_reference'], $file);
     }
     $manager->flush();
 }
Example #2
0
 /**
  * @param string       $filename
  * @param UploadedFile $uploadedFile
  * @param Directory    $directory
  *
  * @return File
  */
 public function save($filename, UploadedFile $uploadedFile, Directory $directory = null)
 {
     if (!$this->isAllowMimeTypes($uploadedFile)) {
         throw new UploadException(sprintf('File type %s is not allowed to upload', $uploadedFile->getMimeType()));
     }
     $newFilePath = $this->uploadDirectoryManager->getNewPath($filename);
     $size = $uploadedFile->getSize();
     $mimeType = $uploadedFile->getMimeType();
     $uploadedFile->move($this->webDir . dirname($newFilePath), basename($newFilePath));
     $path = $this->webDir . $newFilePath;
     if ($this->doResize) {
         $this->resizeImage($path);
     }
     $fileParams = $this->createFileParams($size, $mimeType, $path);
     $file = new File();
     $file->setName($filename);
     $file->setDirectory($directory);
     $file->setPath($newFilePath);
     $file->setChecksum($this->getChecksum($newFilePath));
     $file->setParams($fileParams);
     $this->entityManager->persist($file);
     $this->entityManager->flush();
     return $file;
 }