mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
options parameter extracted at yii\web\Response::xSendFile()
This commit is contained in:
@ -632,11 +632,12 @@ class Response extends \yii\base\Response
|
|||||||
* @param string $filePath file name with full path
|
* @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 $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 $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 array $options additional options. Valid options are:
|
||||||
* @param string $xHeader the name of the x-sendfile header.
|
* - 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
|
* @return static the response object itself
|
||||||
*/
|
*/
|
||||||
public function xSendFile($filePath, $attachmentName = null, $mimeType = null, $forceDownload = true, $xHeader = 'X-Sendfile')
|
public function xSendFile($filePath, $attachmentName = null, $mimeType = null, $options = [])
|
||||||
{
|
{
|
||||||
if ($mimeType === null && ($mimeType = FileHelper::getMimeTypeByExtension($filePath)) === null) {
|
if ($mimeType === null && ($mimeType = FileHelper::getMimeTypeByExtension($filePath)) === null) {
|
||||||
$mimeType = 'application/octet-stream';
|
$mimeType = 'application/octet-stream';
|
||||||
@ -644,7 +645,16 @@ class Response extends \yii\base\Response
|
|||||||
if ($attachmentName === null) {
|
if ($attachmentName === null) {
|
||||||
$attachmentName = basename($filePath);
|
$attachmentName = basename($filePath);
|
||||||
}
|
}
|
||||||
$disposition = $forceDownload ? 'attachment' : 'inline';
|
if (isset($options['xHeader'])) {
|
||||||
|
$xHeader = $options['xHeader'];
|
||||||
|
} else {
|
||||||
|
$xHeader = 'X-Sendfile';
|
||||||
|
}
|
||||||
|
if (!isset($options['forceDownload']) || $options['forceDownload']) {
|
||||||
|
$disposition = 'attachment';
|
||||||
|
} else {
|
||||||
|
$disposition = 'inline';
|
||||||
|
}
|
||||||
|
|
||||||
$this->getHeaders()
|
$this->getHeaders()
|
||||||
->setDefault($xHeader, $filePath)
|
->setDefault($xHeader, $filePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user