浏览代码

Tweaked Validation::extension()

ADmad 14 年之前
父节点
当前提交
76f93178a8
共有 1 个文件被更改,包括 3 次插入4 次删除
  1. 3 4
      lib/Cake/Utility/Validation.php

+ 3 - 4
lib/Cake/Utility/Validation.php

@@ -442,17 +442,16 @@ class Validation {
  * 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(array_pop($pathSegments));
+		$extension = strtolower(pathinfo($check, PATHINFO_EXTENSION));
 		foreach ($extensions as $value) {
 		foreach ($extensions as $value) {
-			if ($extension == strtolower($value)) {
+			if ($extension === strtolower($value)) {
 				return true;
 				return true;
 			}
 			}
 		}
 		}