Skip to content

Instantly share code, notes, and snippets.

@TiuTalk
Created November 3, 2011 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiuTalk/1338259 to your computer and use it in GitHub Desktop.
Save TiuTalk/1338259 to your computer and use it in GitHub Desktop.
<?php
/**
* Classe para fazer verificações de tipos de arquivos
*/
class FileType {
/**
* Lista de extensões válidas para imagens
*
* @var array
*/
public static $image = array('jpg', 'png', 'gif');
/**
* Lista de extensões válidas para documentos
*
* @var array
*/
public static $doc = array('doc', 'docx');
/**
* Verifica se o tipo de arquivo (extensão) está dentro de uma lista válida
*
* @param string $type Tipo de arquivo (extensão)
* @param array $list Lista de extensões válidas
*
* @return boolean
*/
public static function isTypeInList($type, $list) {
return in_array($type, $list);
}
/**
* Verifica se o tipo de arquivo (extensão) é uma imagem
*
* @param string $type Tipo de arquivo (extensão)
*
* @return boolean
*/
public static function isImage($type) {
return self::isTypeInList($type, self::$image);
}
/**
* Verifica se o tipo de arquivo (extensão) é um documento
*
* @param string $type Tipo de arquivo (extensão)
*
* @return boolean
*/
public static function isDoc($type) {
return self::isTypeInList($type, self::$doc);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment