1 | <?php |
||
5 | class Downloader extends Writer |
||
6 | { |
||
7 | /** |
||
8 | * Default headers used to tell client the response is |
||
9 | * a downloadable, non-cacheable file. |
||
10 | * @var array |
||
11 | */ |
||
12 | public static $defaultResponseHeaders = [ |
||
13 | 'Content-Type' => 'application/octet-stream', |
||
14 | 'Content-Description' => 'File Transfer', |
||
15 | 'Content-Transfer-Encoding' => 'Binary', |
||
16 | 'Content-Disposition' => 'attachment; filename="%s"', |
||
17 | 'Expires' => '0', |
||
18 | 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', |
||
19 | 'Pragma' => 'public', |
||
20 | 'Content-Length' => '%s', |
||
21 | ]; |
||
22 | |||
23 | protected $filename; |
||
24 | protected $responseHeaders; |
||
25 | |||
26 | public function __construct($filename = '', $responseHeaders = []) |
||
37 | |||
38 | public function getResponseHeaders() |
||
46 | |||
47 | public function setResponseHeaders($userHeaders = []) |
||
55 | |||
56 | /** |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getFilename() |
||
63 | |||
64 | /** |
||
65 | * @param string $filename |
||
66 | * |
||
67 | * @return Downloader |
||
68 | */ |
||
69 | public function setFilename($filename) |
||
75 | |||
76 | /** |
||
77 | * Attempts to send the file as download to the client. |
||
78 | * |
||
79 | * @throws \Exception |
||
80 | */ |
||
81 | public function download() |
||
106 | |||
107 | protected function getResponseBody() |
||
117 | } |
||
118 |