Exemplo n.º 1
0
 public function fileSave($data, \Uppu4\Entity\User $user, $comment)
 {
     $fileResource = new File();
     $fileResource->setName($data['name']);
     $fileResource->setSize($data['size']);
     $finfo = new \finfo(FILEINFO_MIME_TYPE);
     $fileResource->setExtension($finfo->file($data['tmp_name']));
     $fileResource->setComment($comment);
     $mediainfo = \Uppu4\Entity\MediaInfo::getMediaInfo($data['tmp_name']);
     $fileResource->setMediainfo($mediainfo);
     $fileResource->setUploaded();
     $fileResource->setUploadedBy($user);
     $this->em->getConnection()->beginTransaction();
     $this->em->persist($fileResource);
     $this->em->flush();
     $id = $fileResource->getId();
     $tmpFile = $data['tmp_name'];
     $newFile = FormatHelper::formatUploadLink($id, $data['name']);
     if (move_uploaded_file($tmpFile, $newFile)) {
         if (in_array($fileResource->getExtension(), $this->pictures)) {
             $path = FormatHelper::formatUploadResizeLink($id, $data['name']);
             $resize = new Resize();
             $resize->resizeFile($newFile, $path);
         }
         $this->em->getConnection()->commit();
         return $fileResource;
     } else {
         $this->em->getConnection()->rollback();
     }
 }
Exemplo n.º 2
0
 public function convertToPHPValue($info)
 {
     $info = json_decode($info);
     $mediaInfo = \Uppu4\Entity\MediaInfo::setMediaInfo($info);
     return $mediaInfo;
 }