From 6088ba9da1623ecff5589010a11f2a7e2deca136 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 12 Feb 2009 15:54:55 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSformRule=5Fmimetype=20:=20Ajout=20d'une?= =?UTF-8?q?=20nouvelle=20r=C3=A8gle=20de=20validation=20sur=20le=20mimetyp?= =?UTF-8?q?e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class/class.LSformRule_mimetype.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 trunk/includes/class/class.LSformRule_mimetype.php diff --git a/trunk/includes/class/class.LSformRule_mimetype.php b/trunk/includes/class/class.LSformRule_mimetype.php new file mode 100644 index 00000000..4fbc8ac0 --- /dev/null +++ b/trunk/includes/class/class.LSformRule_mimetype.php @@ -0,0 +1,70 @@ + + */ +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 + */ + function validate ($value,$options,$formElement) { + $file = LSsession :: getTmpFile($value); + + $mimetype = mime_content_type($file); + + if (isset($options['params']['mimeType'])) { + if (is_array($options['params']['mimeType'])) { + if (!in_array($mimetype,$options['params']['mimeType'])) { + return; + } + } + else { + if ($mimetype != $options['params']['mimeType']) { + return; + } + } + } + + if (isset($options['params']['mimeTypeRegEx'])) { + if (!preg_match($options['params']['mimeTypeRegEx'], $mimetype)) { + return false; + } + } + + return true; + } + +} + +?>