Пример #1
0
 /**
  * isMime('img/png', array('jpg', 'png')
  * 
  * @param unknown_type $value
  * @param unknown_type $types
  */
 public static function isMime($value, $types)
 {
     $types = (array) $types;
     foreach ($types as $type) {
         if (\Hub\File\Mime::getAlias($value) == $type) {
             return true;
         }
     }
     return false;
 }
Пример #2
0
 private function validate()
 {
     foreach ($this->mimeValidator['type'] as $type) {
         if (\Hub\File\Mime::getType($this->mimeValidator['type']) != $this->type) {
             $this->isValid = false;
             $this->errorMessage = $this->mimeValidator['msg'];
             $this->isValidated = true;
             return;
         }
     }
     /*$size = self::fromByteString($this->size);
     		
     		if ( ( $size == self::fromByteString($this->sizeValidator['min']) ) || ($size >= self::fromByteString($this->sizeValidator['max']) ) )
     		{
     			$this->isValid = false;
     			
     			$this->errorMessage = $this->sizeValidator['msg'];
     			
     			$this->isValidated = true;
     			
     			return;
     		}*/
     switch ($this->error) {
         case UPLOAD_ERR_OK:
             $this->isValid = true;
             continue;
         case UPLOAD_ERR_INI_SIZE:
             // public error
             $this->isValid = false;
             $this->errorMessage = 'The uploaded file exceeds the maximum allowed file size';
             return false;
             break;
         case UPLOAD_ERR_NO_FILE:
             // public error
             $this->isValid = false;
             $this->errorMessage = 'No file selected.';
             return false;
             break;
         case UPLOAD_ERR_PARTIAL:
             // public error
             $this->isValid = false;
             $this->errorMessage = 'The uploaded file was only partially uploaded. Please try again!';
             return false;
             break;
         case UPLOAD_ERR_CANT_WRITE:
             // system error
             $this->isValid = false;
             throw new \LogicException('Failed to write file to disk. Check Upload directory write permissions');
             break;
         case UPLOAD_ERR_EXTENSION:
             // system error
             $this->isValid = false;
             throw new \LogicException('A PHP extension stopped the file upload');
             break;
         default:
             $this->isValid = false;
             $this->errorMessage = 'Unknown error occured';
             break;
     }
     $this->isValidated = true;
 }