예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function prePersist(MediaInterface $media)
 {
     if (is_null($file = $media->getFile())) {
         return;
     }
     parent::prePersist($media);
     $size = getimagesize($file);
     $media->setMetadata(['width' => $size[0], 'height' => $size[1]]);
 }
예제 #2
0
 /**
  * Upload a file.
  *
  * @param MediaInterface $media
  */
 public function upload(MediaInterface $media)
 {
     // the file property can be empty if the field is not required
     if (null === $media->getFile()) {
         return;
     }
     $adapter = $this->filesystem->getAdapter();
     if ($adapter instanceof AwsS3) {
         $adapter->setMetadata($media->getReference(), ['ContentType' => $media->getContentType()]);
     }
     $this->filesystem->write($media->getReference(), file_get_contents($media->getFile()));
     if (isset($media->temp)) {
         // delete the old image
         unlink($media->temp);
         // clear the temp image path
         $media->temp = null;
     }
     // clean up the file property as you won't need it anymore
     $media->setFile(null);
 }