Exemplo n.º 1
0
 /**
  * Validate
  *
  * @param  \Upload\FileInfoInterface $fileInfo
  * @throws \RuntimeException         If validation fails
  */
 public function validate(FileInfoInterface $fileInfo)
 {
     $fileExtension = strtolower($fileInfo->getExtension());
     if (in_array($fileExtension, $this->allowedExtensions) === false) {
         throw new Exception(sprintf('Invalid file extension. Must be one of: %s', implode(', ', $this->allowedExtensions)), $fileInfo);
     }
 }
Exemplo n.º 2
0
 /**
  * Validate
  *
  * @param  \Upload\FileInfoInterface  $fileInfo
  * @throws \RuntimeException          If validation fails
  */
 public function validate(FileInfoInterface $fileInfo)
 {
     //Profiler::debugPoint(true,__METHOD__, __FILE__, __LINE__,$this->mimetypes);
     if (in_array($fileInfo->getMimetype(), $this->mimetypes) === false) {
         Profiler::debugPoint(true, __METHOD__, __FILE__, __LINE__, $this->mimetypes);
         throw new Exception(sprintf('Invalid mimetype. Must be one of: %s', implode(', ', $this->mimetypes)), $fileInfo);
     }
 }
Exemplo n.º 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 Exception('File already exists', $fileInfo);
     }
     if ($this->moveUploadedFile($fileInfo->getPathname(), $destinationFile) === false) {
         throw new Exception('File could not be moved to final destination.', $fileInfo);
     }
 }
Exemplo n.º 4
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);
     }
 }