Ejemplo n.º 1
0
 /**
  * Test if an file is an allowed file type, by extension.
  *
  *     $validate->rule('file', 'Ku_File::type', array('jpg, png, gif'));
  *     $validate->rule('file', 'Ku_File::type', array('.JPG, .PNG, .GIF'));
  *
  * @param   mixed    $_FILES item or filepath
  * @param   string    allowed file extensions
  * @return  bool
  */
 public static function type($file, $allowed)
 {
     if (is_string($allowed)) {
         $allowed = explode(',', str_replace('.', '', $allowed));
         $allowed = array_map('trim', $allowed);
     }
     $allowed = array_map('strtolower', $allowed);
     if (is_array($file)) {
         return Ku_Upload::type($file, $allowed);
     }
     if (empty($file) or basename($file) == $file) {
         return TRUE;
     }
     $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
     return in_array($ext, $allowed);
 }