mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Added forceDownload parameter to yii\web\Response::xSendFile()
This commit is contained in:
@ -172,6 +172,7 @@ Yii Framework 2 Change Log
|
||||
- Enh #4317: Added `absoluteAuthTimeout` to yii\web\User (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)
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -632,10 +632,11 @@ 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 boolean $forceDownload whether the file will be downloaded or shown inline.
|
||||
* @param string $xHeader the name of the x-sendfile header.
|
||||
* @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, $forceDownload = true, $xHeader = 'X-Sendfile')
|
||||
{
|
||||
if ($mimeType === null && ($mimeType = FileHelper::getMimeTypeByExtension($filePath)) === null) {
|
||||
$mimeType = 'application/octet-stream';
|
||||
@ -643,11 +644,12 @@ class Response extends \yii\base\Response
|
||||
if ($attachmentName === null) {
|
||||
$attachmentName = basename($filePath);
|
||||
}
|
||||
$disposition = $forceDownload ? 'attachment' : 'inline';
|
||||
|
||||
$this->getHeaders()
|
||||
->setDefault($xHeader, $filePath)
|
||||
->setDefault('Content-Type', $mimeType)
|
||||
->setDefault('Content-Disposition', "attachment; filename=\"$attachmentName\"");
|
||||
->setDefault('Content-Disposition', "{$disposition}; filename=\"{$attachmentName}\"");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user