Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
d8e43b7c
Commit
d8e43b7c
authored
Dec 04, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor fixed for file upload guide
parent
0fd0f430
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
input-file-upload.md
docs/guide/input-file-upload.md
+27
-4
No files found.
docs/guide/input-file-upload.md
View file @
d8e43b7c
...
@@ -51,14 +51,15 @@ Next, create a view that will render the form:
...
@@ -51,14 +51,15 @@ Next, create a view that will render the form:
```
php
```
php
<?php
<?php
use
yii\widgets\ActiveForm
;
use
yii\widgets\ActiveForm
;
?>
$form
=
ActiveForm
::
begin
([
'options'
=>
[
'enctype'
=>
'multipart/form-data'
]]);
?>
<?php
$form
=
ActiveForm
::
begin
([
'options'
=>
[
'enctype'
=>
'multipart/form-data'
]])
?>
<?=
$form
->
field
(
$model
,
'file'
)
->
fileInput
()
?>
<?=
$form
->
field
(
$model
,
'file'
)
->
fileInput
()
?>
<button>
Submit
</button>
<button>
Submit
</button>
<?php
ActiveForm
::
end
()
;
?>
<?php
ActiveForm
::
end
()
?>
```
```
The
`'enctype' => 'multipart/form-data'`
is necessary because it allows file uploads.
`fileInput()`
represents a form
The
`'enctype' => 'multipart/form-data'`
is necessary because it allows file uploads.
`fileInput()`
represents a form
...
@@ -86,7 +87,7 @@ class SiteController extends Controller
...
@@ -86,7 +87,7 @@ class SiteController extends Controller
if
(
Yii
::
$app
->
request
->
isPost
)
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
$model
->
file
=
UploadedFile
::
getInstance
(
$model
,
'file'
);
$model
->
file
=
UploadedFile
::
getInstance
(
$model
,
'file'
);
if
(
$model
->
validate
())
{
if
(
$model
->
file
&&
$model
->
validate
())
{
$model
->
file
->
saveAs
(
'uploads/'
.
$model
->
file
->
baseName
.
'.'
.
$model
->
file
->
extension
);
$model
->
file
->
saveAs
(
'uploads/'
.
$model
->
file
->
baseName
.
'.'
.
$model
->
file
->
extension
);
}
}
}
}
...
@@ -162,7 +163,29 @@ received a valid image that can be then either saved or processed using the [Ima
...
@@ -162,7 +163,29 @@ received a valid image that can be then either saved or processed using the [Ima
### Uploading multiple files
### Uploading multiple files
If you need to download multiple files at once, some adjustments are required.
If you need to download multiple files at once, some adjustments are required.
Model:
```
php
class
UploadForm
extends
Model
{
/**
* @var UploadedFile|Null file attribute
*/
public
$file
;
/**
* @return array the validation rules.
*/
public
function
rules
()
{
return
[
[[
'file'
],
'file'
,
'maxFiles'
=>
10
],
// <--- here!
];
}
}
```
View:
View:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment