예제 #1
0
 public function saveFile(FileInterface $file)
 {
     $fileEntity = new File($file);
     $this->em->persist($fileEntity);
     $this->em->flush();
     $file->setId($fileEntity->getId());
 }
예제 #2
0
 /**
  * @param FileInterface $file
  * @return bool
  * @throws FileExtensionNotAllowedException
  */
 public function filter(FileInterface $file)
 {
     $fileExtension = $file->getExtension();
     if (in_array(strtolower($fileExtension), $this->allowedExtensions)) {
         return true;
     } else {
         throw new FileExtensionNotAllowedException("File Extension Not Allowed: " . $fileExtension, $file);
     }
 }
예제 #3
0
 /**
  * @param FileInterface $file
  * @return bool
  * @throws FileSizeNotAllowedException
  */
 public function filter(FileInterface $file)
 {
     $fileSize = $file->getSize();
     if ($fileSize <= $this->size) {
         return true;
     } else {
         throw new FileSizeNotAllowedException("File Extension Not Allowed: " . $fileSize, 800);
     }
 }
예제 #4
0
 public function publish(FileInterface $file)
 {
     $fileType = $file->getExtension();
     $fileUploadLink = $file->getPath();
     $fileName = $file->getNameKey() . "." . $fileType;
     if ($file instanceof Image) {
         if ($file->isProcessed()) {
             $size = $file->getImageSize();
             $folder = $size->getWidth() . 'x' . $size->getHeight();
         } else {
             $folder = "original";
         }
     } else {
         $folder = "files";
     }
     $this->s3Client->putObject(array('Bucket' => $this->bucket, 'Key' => $this->url . $this->subfolder . $folder . '/' . $fileName, 'Body' => file_get_contents($fileUploadLink), 'ACL' => 'public-read', 'ContentType' => $file->getType()));
 }
예제 #5
0
 public function saveFile(FileInterface $file)
 {
     $target_file = "";
     try {
         $target_file = $this->targetDir . $file->getOriginalName();
         if (!$this->applyFilters($file)) {
             throw new FilterException("File did not pass the filters", $file);
         }
         move_uploaded_file($file->getPath() . "/" . $file->getName(), $target_file);
         $nameKey = md5(microtime() . rand());
         $file->setNameKey($nameKey);
         $file->setPath($target_file);
         $this->applyProcessors($file);
     } catch (\Exception $e) {
         //            unlink($target_file);
         throw $e;
     }
 }