*/ class LSformRule_mimetype extends LSformRule { /** * Vérification de la valeur. * * @param string $values Valeur à vérifier * @param array $options Options de validation : * - Type MIME : $options['params']['mimeType'] * - Type MIME (regex) : $options['params']['mimeTypeRegEx'] * @param object $formElement L'objet formElement attaché * * @return boolean true si la valeur est valide, false sinon */ public static function validate ($value,$options,$formElement) { $file = LSsession :: getTmpFile($value); $real_mimetype = mime_content_type($file); $mimetype = LSconfig :: get('params.mimeType', null, null, $options); if (!is_null($mimetype)) { if (is_array($mimetype)) { if (!in_array($real_mimetype, $mimetype)) return; } else { if ($real_mimetype != $mimetype) return; } } $mimeTypeRegEx = LSconfig :: get('params.mimeTypeRegEx', null, 'string', $options); if (is_string($mimeTypeRegEx) && !preg_match($mimeTypeRegEx, $real_mimetype)) return false; return true; } }