Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added regex support to Validation::mimeType().

  • Loading branch information...
commit 2d10707d18c82575849b52609aac612a39bbd6cb 1 parent 6eb5a38
@ADmad ADmad authored
View
3  lib/Cake/Test/Case/Utility/ValidationTest.php
@@ -2356,9 +2356,12 @@ public function testDatetime() {
public function testMimeType() {
$image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
$File = new File($image, false);
+
$this->skipIf(!$File->mime(), 'Cannot determine mimeType');
+
$this->assertTrue(Validation::mimeType($image, array('image/gif')));
$this->assertTrue(Validation::mimeType(array('tmp_name' => $image), array('image/gif')));
+ $this->assertTrue(Validation::mimeType(array('tmp_name' => $image), '#image/.+#'));
$this->assertFalse(Validation::mimeType($image, array('image/GIF')));
$this->assertFalse(Validation::mimeType($image, array('image/png')));
View
9 lib/Cake/Utility/Validation.php
@@ -925,10 +925,10 @@ public static function luhn($check, $deep = false) {
}
/**
- * Checks the mime type of a file. Comparison is case sensitive.
+ * Checks the mime type of a file.
*
* @param string|array $check
- * @param array $mimeTypes to check for
+ * @param array|string $mimeTypes Array of mime types or regex pattern to check.
* @return boolean Success
* @throws CakeException when mime type can not be determined.
*/
@@ -943,6 +943,11 @@ public static function mimeType($check, $mimeTypes = array()) {
if ($mime === false) {
throw new CakeException(__d('cake_dev', 'Can not determine the mimetype.'));
}
+
+ if (is_string($mimeTypes)) {
+ return self::_check($mime, $mimeTypes);
+ }
+
return in_array($mime, $mimeTypes);
}
Please sign in to comment.
Something went wrong with that request. Please try again.