Exemple #1
0
 /**
  * Validate
  *
  * @param  \Upload\FileInfoInterface $fileInfo
  * @throws \RuntimeException         If validation fails
  */
 public function validate(\Upload\FileInfoInterface $fileInfo)
 {
     $fileExtension = strtolower($fileInfo->getExtension());
     if (in_array($fileExtension, $this->allowedExtensions) === false) {
         throw new \Upload\Exception(sprintf('Invalid file extension. Must be one of: %s', implode(', ', $this->allowedExtensions)), $fileInfo);
     }
 }
Exemple #2
0
 /**
  * Validate
  *
  * @param  \Upload\FileInfoInterface  $fileInfo
  * @throws \RuntimeException          If validation fails
  */
 public function validate(FileInfoInterface $fileInfo)
 {
     $fileSize = $fileInfo->getSize();
     if ($fileSize < $this->minSize) {
         throw new Exception(sprintf('File size is too small. Must be greater than or equal to: %s', $this->minSize), $fileInfo);
     }
     if ($fileSize > $this->maxSize) {
         throw new Exception(sprintf('File size is too large. Must be less than: %s', $this->maxSize), $fileInfo);
     }
 }
Exemple #3
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);
     }
 }
Exemple #4
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));
     }
 }
Exemple #5
0
 /**
  * Validate
  *
  * @param  \Upload\FileInfoInterface  $fileInfo
  * @throws \RuntimeException          If validation fails
  */
 public function validate(\Upload\FileInfoInterface $fileInfo)
 {
     if (in_array($fileInfo->getMimetype(), $this->mimetypes) === false) {
         throw new \Upload\Exception(sprintf('Invalid mimetype. Must be one of: %s', implode(', ', $this->mimetypes)), $fileInfo);
     }
 }