Elgg  Version 6.1
DownloadResponse.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Http;
4 
11 
15  public function getHeaders() {
16  $headers = parent::getHeaders();
17 
18  if (!isset($headers['Content-Type'])) {
19  $headers['Content-Type'] = 'application/octet-stream; charset=utf-8';
20  }
21 
22  if (!isset($headers['Cache-Control'])) {
23  $headers['Cache-Control'] = 'no-store';
24  }
25 
26  if (!isset($headers['Content-Disposition'])) {
27  $headers['Content-Disposition'] = 'attachment';
28  }
29 
30  if (!empty($this->content) && !isset($headers['Content-Length'])) {
31  $headers['Content-Length'] = strlen((string) $this->content);
32  }
33 
34  return $headers;
35  }
36 
40  public function setForwardURL(string $forward_url = REFERRER) {
41  return $this;
42  }
43 
54  public function setFilename(string $filename = '', bool $inline = false): static {
55  if (isset($this->headers['Content-Disposition'])) {
56  return $this;
57  }
58 
59  $disposition = $inline ? 'inline' : 'attachment';
60 
61  if (!elgg_is_empty($filename)) {
62  $disposition .= "; filename=\"{$filename}\"";
63  }
64 
65  $this->headers['Content-Disposition'] = $disposition;
66 
67  return $this;
68  }
69 }
string $forward_url
Definition: Response.php:20
$inline
Definition: save.php:22
getHeaders()
Returns additional response headers.array
setFilename(string $filename= '', bool $inline=false)
Set the filename for the download.
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
const REFERRER
Used in calls to forward() to specify the browser should be redirected to the referring page...
Definition: constants.php:37
Download response builder.
OK response builder.
Definition: OkResponse.php:8
setForwardURL(string $forward_url=REFERRER)
Sets redirect URL.Forward URL self