Skip to content

Commit 4ca6e12

Browse files
committed
Merge branch 'master' of github.com:activecollab/controller
# Conflicts: # src/Response/FileDownloadResponse.php
2 parents a0fe369 + c01418c commit 4ca6e12

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Response/FileDownloadResponse.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,28 @@ class FileDownloadResponse implements ResponseInterface
4747
*/
4848
private $x_type;
4949

50+
/**
51+
* @var string|null
52+
*/
53+
private $x_accel_redirect_to;
54+
5055
/**
5156
* @param string $file
5257
* @param string $content_type
5358
* @param bool $inline
5459
* @param string|null $filename
5560
* @param string|null $cache_hash
5661
* @param string|null $x_type
62+
* @param string|null $x_accel_redirect_to
5763
*/
5864
public function __construct(
5965
$file,
6066
$content_type,
6167
$inline = false,
6268
$filename = null,
6369
$cache_hash = null,
64-
$x_type = null
70+
$x_type = null,
71+
$x_accel_redirect_to = null
6572
)
6673
{
6774
if (!is_file($file)) {
@@ -74,14 +81,24 @@ public function __construct(
7481
$this->filename = $filename;
7582
$this->cache_hash = $cache_hash;
7683
$this->x_type = $x_type;
84+
$this->x_accel_redirect_to = $x_accel_redirect_to;
7785
}
7886

7987
public function createPsrResponse()
8088
{
89+
$response = new Response();
8190
$filename = $this->filename ?: basename($this->file);
8291
$disposition = $this->inline ? 'inline' : 'attachment';
8392

84-
$response = new Response();
93+
if (!empty($this->x_accel_redirect_to)) {
94+
$response = $response
95+
->withHeader('Content-Disposition', $disposition . '; filename="' . $filename . '"')
96+
->withHeader('Content-Length', filesize($this->file))
97+
->withHeader('X-Accel-Redirect', $this->x_accel_redirect_to . $filename);
98+
99+
return $response;
100+
}
101+
85102
$stream = new Stream(fopen($this->file, 'rb'));
86103

87104
/** @var Response $response */

0 commit comments

Comments
 (0)