コード例 #1
0
ファイル: Extension.php プロジェクト: negati-ve/prote
 /**
  * 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);
     }
 }
コード例 #2
0
ファイル: Size.php プロジェクト: rocketpastsix/Upload
 /**
  * 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);
     }
 }
コード例 #3
0
ファイル: FileSystem.php プロジェクト: rocketpastsix/Upload
 /**
  * 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);
     }
 }
コード例 #4
0
ファイル: Dimensions.php プロジェクト: kuslahne/Upload
 /**
  * @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));
     }
 }
コード例 #5
0
ファイル: Mimetype.php プロジェクト: rocketpastsix/Upload
 /**
  * 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);
     }
 }