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
a3e7a33a
Commit
a3e7a33a
authored
Aug 19, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4748 from klimov-paul/4424-x-send-file
Enh #4424: Added `forceDownload` parameter to `yii\web\Response::xSendFile()`
parents
a56490e0
fe36bc9e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
3 deletions
+19
-3
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
UPGRADE.md
framework/UPGRADE.md
+3
-0
Response.php
framework/web/Response.php
+15
-3
No files found.
framework/CHANGELOG.md
View file @
a3e7a33a
...
...
@@ -173,6 +173,7 @@ Yii Framework 2 Change Log
-
Enh #4317: Added
`absoluteAuthTimeout`
to yii
\w
eb
\U
ser (ivokund, nkovacs)
-
Enh #4360: Added client validation support for file validator (Skysplit)
-
Enh #4372:
`yii\filters\HttpCache`
failed to comply to RFC 7232 (DaSourcerer)
-
Enh #4424: Added
`forceDownload`
parameter to
`yii\web\Response::xSendFile()`
(klimov-paul)
-
Enh #4436: Added callback functions to AJAX-based form validation (thiagotalma)
-
Enh #4485: Added support for deferred validation in
`ActiveForm`
(Alex-Code)
-
Enh #4520: Added sasl support to
`yii\caching\MemCache`
(xjflyttp)
...
...
framework/UPGRADE.md
View file @
a3e7a33a
...
...
@@ -196,3 +196,6 @@ new ones save the following code as `convert.php` that should be placed in the s
*
The format of the Faker fixture template is changed. For an example, please refer to the file
`apps/advanced/common/tests/templates/fixtures/user.php`
.
*
Signature of the
`yii\web\Response::xSendFile()`
method has changed. If you're using or overriding this method you
must change your code to fit it.
framework/web/Response.php
View file @
a3e7a33a
...
...
@@ -632,10 +632,12 @@ class Response extends \yii\base\Response
* @param string $filePath file name with full path
* @param string $attachmentName file name shown to the user. If null, it will be determined from `$filePath`.
* @param string $mimeType the MIME type of the file. If null, it will be determined based on `$filePath`.
* @param string $xHeader the name of the x-sendfile header.
* @param array $options additional options. Valid options are:
* - forceDownload: boolean, whether the file will be downloaded or shown inline. Defaults to true.
* - xHeader: string, the name of the x-sendfile header. Defaults to "X-Sendfile".
* @return static the response object itself
*/
public
function
xSendFile
(
$filePath
,
$attachmentName
=
null
,
$mimeType
=
null
,
$
xHeader
=
'X-Sendfile'
)
public
function
xSendFile
(
$filePath
,
$attachmentName
=
null
,
$mimeType
=
null
,
$
options
=
[]
)
{
if
(
$mimeType
===
null
&&
(
$mimeType
=
FileHelper
::
getMimeTypeByExtension
(
$filePath
))
===
null
)
{
$mimeType
=
'application/octet-stream'
;
...
...
@@ -643,11 +645,21 @@ class Response extends \yii\base\Response
if
(
$attachmentName
===
null
)
{
$attachmentName
=
basename
(
$filePath
);
}
if
(
isset
(
$options
[
'xHeader'
]))
{
$xHeader
=
$options
[
'xHeader'
];
}
else
{
$xHeader
=
'X-Sendfile'
;
}
if
(
!
isset
(
$options
[
'forceDownload'
])
||
$options
[
'forceDownload'
])
{
$disposition
=
'attachment'
;
}
else
{
$disposition
=
'inline'
;
}
$this
->
getHeaders
()
->
setDefault
(
$xHeader
,
$filePath
)
->
setDefault
(
'Content-Type'
,
$mimeType
)
->
setDefault
(
'Content-Disposition'
,
"
attachment; filename=
\"
$attachmentName
\"
"
);
->
setDefault
(
'Content-Disposition'
,
"
{
$disposition
}
; filename=
\"
{
$attachmentName
}
\"
"
);
return
$this
;
}
...
...
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