Skip to content

Commit

Permalink
Tweaked Validation::extension()
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 25, 2012
1 parent ad53458 commit 76f9317
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/Cake/Utility/Validation.php
Expand Up @@ -442,17 +442,16 @@ public static function equalTo($check, $comparedTo) {
* Check that value has a valid file extension. * Check that value has a valid file extension.
* *
* @param string|array $check Value to check * @param string|array $check Value to check
* @param array $extensions file extensions to allow * @param array $extensions file extensions to allow. By default extensions are 'gif', 'jpeg', 'png', 'jpg'
* @return boolean Success * @return boolean Success
*/ */
public static function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg')) { public static function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg')) {
if (is_array($check)) { if (is_array($check)) {
return self::extension(array_shift($check), $extensions); return self::extension(array_shift($check), $extensions);
} }
$pathSegments = explode('.', $check); $extension = strtolower(pathinfo($check, PATHINFO_EXTENSION));
$extension = strtolower(array_pop($pathSegments));
foreach ($extensions as $value) { foreach ($extensions as $value) {
if ($extension == strtolower($value)) { if ($extension === strtolower($value)) {
return true; return true;
} }
} }
Expand Down

0 comments on commit 76f9317

Please sign in to comment.