From f98554b13a830aafc4709e2125a1eeb81513cb03 Mon Sep 17 00:00:00 2001 From: Christopher Vrooman Date: Fri, 28 Nov 2014 13:45:09 -0300 Subject: [PATCH] Update input-file-upload.md Minor syntax changes. --- docs/guide/input-file-upload.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/guide/input-file-upload.md b/docs/guide/input-file-upload.md index c5e2d843db..f0ee70c242 100644 --- a/docs/guide/input-file-upload.md +++ b/docs/guide/input-file-upload.md @@ -3,7 +3,7 @@ Uploading Files > Note: This section is under development. -Uploading files in Yii is done via the form model, its validation rules and some controller code. Let's review what's needed +Uploading files in Yii is done via the a form model, its validation rules and some controller code. Let's review what's needed to handle uploads properly. Form model @@ -46,7 +46,7 @@ the HTML form. The attribute has the validation rule named `file` that uses [[yi Form view --------- -Next create a view that will render the form. +Next, create a view that will render the form: ```php ['enctype' => 'multipart/form-data']]); ``` -The `'enctype' => 'multipart/form-data'` is important since it allows file uploads. `fileInput()` represents a form +The `'enctype' => 'multipart/form-data'` is necessary because it allows file uploads. `fileInput()` represents a form input field. Controller @@ -96,10 +96,8 @@ class SiteController extends Controller } ``` -Instead of `model->load(...)` we are using `UploadedFile::getInstance(...)`. [[\yii\web\UploadedFile|UploadedFile]] -does not run the model validation. It only provides information about the uploaded file. Therefore, you need to run -validation manually via `$model->validate()`. This triggers the [[yii\validators\FileValidator|FileValidator]] that -expects a file: +Instead of `model->load(...)`, we are using `UploadedFile::getInstance(...)`. [[\yii\web\UploadedFile|UploadedFile]] +does not run the model validation, rather it only provides information about the uploaded file. Therefore, you need to run the validation manually via `$model->validate()` to trigger the [[yii\validators\FileValidator|FileValidator]] that expects a file: ```php $file instanceof UploadedFile || $file->error == UPLOAD_ERR_NO_FILE //in the code framework @@ -144,7 +142,7 @@ public function rules() } ``` -Keep in mind that only the file extension will be validated, but not the actual file content. In order to validate content as well use the `mimeTypes` property of `FileValidator`: +Keep in mind that only the file extension will be validated, but not the actual file content. In order to validate the content as well, use the `mimeTypes` property of `FileValidator`: ```php public function rules() @@ -164,7 +162,9 @@ received a valid image that can be then either saved or processed using the [Ima ### Uploading multiple files -If you need to download multiple files at once some adjustments are required. View: +If you need to download multiple files at once, some adjustments are required. + +View: ```php