From 66c6268e5fdb56f02df2335ef4816c21a9ad7313 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Wed, 24 Feb 2016 09:05:29 +0200 Subject: [PATCH] FileValidator: updated guide-ru,en, PHP; updated tests --- docs/guide-ru/tutorial-core-validators.md | 5 ++++- docs/guide/tutorial-core-validators.md | 2 ++ framework/validators/FileValidator.php | 7 +++---- tests/framework/validators/FileValidatorTest.php | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/guide-ru/tutorial-core-validators.md b/docs/guide-ru/tutorial-core-validators.md index 8ae84ef7bd..bd56962388 100644 --- a/docs/guide-ru/tutorial-core-validators.md +++ b/docs/guide-ru/tutorial-core-validators.md @@ -240,7 +240,10 @@ function foo($model, $attribute) { допустимы. - `mimeTypes`: список MIME-типов, которые допустимы для загрузки. Это может быть или массив, или строка, содержащая MIME-типы файлов, разделенные пробелом или запятой (пример: "image/jpeg, image/png"). - Имена mime-типов не чувствительны к регистру. По умолчанию - null, что значит, что допустимы все MIME-типы. + В именах MIME-типов допустимо использовать символ `*` для выбора группы mime-типов. + Например, `image/*` разрешит все типы, которы начинаются с `image/` (пример: `image/jpeg`, `image/png`). + Имена MIME-типов не чувствительны к регистру. По умолчанию - null, что значит, что допустимы все MIME-типы. + Более детальную информацию можно найти в [списке MIME-типов](https://ru.wikipedia.org/wiki/Список_MIME-типов). - `minSize`: минимальный размер файла в байтах, разрешенный для загрузки. По умолчанию - null, что значит, что нет минимального лимита. - `maxSize`: максимальный размер файла в байтах, разрешенный для загрузки. По умолчанию - null, что значит, что нет diff --git a/docs/guide/tutorial-core-validators.md b/docs/guide/tutorial-core-validators.md index 75e6f1e1b5..ebfb57b8fc 100644 --- a/docs/guide/tutorial-core-validators.md +++ b/docs/guide/tutorial-core-validators.md @@ -294,6 +294,8 @@ This validator checks if the input is a valid uploaded file. extensions are allowed. - `mimeTypes`: a list of file MIME types that are allowed to be uploaded. This can be either an array or a string consisting of file MIME types separated by space or comma (e.g. "image/jpeg, image/png"). + The wildcard mask with the special character `*` can be used to match groups of mime types. + For example `image/*` will pass all mime types, that begin with `image/` (e.g. `image/jpeg`, `image/png`). Mime type names are case-insensitive. Defaults to null, meaning all MIME types are allowed. For more details, please refer to [common media types](http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types). - `minSize`: the minimum number of bytes required for the uploaded file. Defaults to null, meaning no lower limit. diff --git a/framework/validators/FileValidator.php b/framework/validators/FileValidator.php index d0ec892b5d..d0b4158919 100644 --- a/framework/validators/FileValidator.php +++ b/framework/validators/FileValidator.php @@ -44,10 +44,9 @@ class FileValidator extends Validator * @var array|string a list of file MIME types that are allowed to be uploaded. * This can be either an array or a string consisting of file MIME types * separated by space or comma (e.g. "text/plain, image/png"). - * Mime type names are case-insensitive. Defaults to null, meaning all MIME types - * are allowed. - * The wildcard mask with the special character `*` can be used to match groups of mime types. - * For example `image/*` will pass all mime types, that begin with `image/` (e.g. `image/jpeg`, `image/png`) + * The mask with the special character `*` can be used to match groups of mime types. + * For example `image/*` will pass all mime types, that begin with `image/` (e.g. `image/jpeg`, `image/png`). + * Mime type names are case-insensitive. Defaults to null, meaning all MIME types are allowed. * @see wrongMimeType for the customized message for wrong MIME type. */ public $mimeTypes; diff --git a/tests/framework/validators/FileValidatorTest.php b/tests/framework/validators/FileValidatorTest.php index 3b37187264..282f69fd84 100644 --- a/tests/framework/validators/FileValidatorTest.php +++ b/tests/framework/validators/FileValidatorTest.php @@ -375,6 +375,7 @@ class FileValidatorTest extends TestCase return [ ['test.jpg', 'image/*'], ['test.png', 'image/*'], + ['test.png', 'IMAGE/*'], ['test.txt', 'text/*'], ['test.xml', '*/xml'], ['test.odt', 'application/vnd*']