@@ -47,21 +47,28 @@ class FileDownloadResponse implements ResponseInterface
47
47
*/
48
48
private $ x_type ;
49
49
50
+ /**
51
+ * @var string|null
52
+ */
53
+ private $ x_accel_redirect_to ;
54
+
50
55
/**
51
56
* @param string $file
52
57
* @param string $content_type
53
58
* @param bool $inline
54
59
* @param string|null $filename
55
60
* @param string|null $cache_hash
56
61
* @param string|null $x_type
62
+ * @param string|null $x_accel_redirect_to
57
63
*/
58
64
public function __construct (
59
65
$ file ,
60
66
$ content_type ,
61
67
$ inline = false ,
62
68
$ filename = null ,
63
69
$ cache_hash = null ,
64
- $ x_type = null
70
+ $ x_type = null ,
71
+ $ x_accel_redirect_to = null
65
72
)
66
73
{
67
74
if (!is_file ($ file )) {
@@ -74,14 +81,24 @@ public function __construct(
74
81
$ this ->filename = $ filename ;
75
82
$ this ->cache_hash = $ cache_hash ;
76
83
$ this ->x_type = $ x_type ;
84
+ $ this ->x_accel_redirect_to = $ x_accel_redirect_to ;
77
85
}
78
86
79
87
public function createPsrResponse ()
80
88
{
89
+ $ response = new Response ();
81
90
$ filename = $ this ->filename ?: basename ($ this ->file );
82
91
$ disposition = $ this ->inline ? 'inline ' : 'attachment ' ;
83
92
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
+
85
102
$ stream = new Stream (fopen ($ this ->file , 'rb ' ));
86
103
87
104
/** @var Response $response */
0 commit comments