Example #1
0
 /**
  * Upload
  *
  * @param  \Upload\FileInfoInterface $file The file object to upload
  * @throws \Upload\Exception               If overwrite is false and file already exists
  * @throws \Upload\Exception               If error moving file to destination
  */
 public function upload(FileInfoInterface $fileInfo)
 {
     $destinationFile = $this->directory . $fileInfo->getNameWithExtension();
     if ($this->overwrite === false && file_exists($destinationFile) === true) {
         throw new \Upload\Exception('File already exists', $fileInfo);
     }
     if ($this->moveUploadedFile($fileInfo->getPathname(), $destinationFile) === false) {
         throw new \Upload\Exception('File could not be moved to final destination.', $fileInfo);
     }
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function validate(FileInfoInterface $info)
 {
     $dimensions = $info->getDimensions();
     $filename = $info->getNameWithExtension();
     if (!$dimensions) {
         throw new Exception(sprintf('%s: Could not detect image size.', $filename));
     }
     if ($dimensions['width'] != $this->width) {
         throw new Exception(sprintf('%s: Image width(%dpx) does not match required width(%dpx)', $filename, $dimensions['width'], $this->width));
     }
     if ($dimensions['height'] != $this->height) {
         throw new Exception(sprintf('%s: Image height(%dpx) does not match required height(%dpx)', $filename, $dimensions['height'], $this->height));
     }
 }