Elgg  Version 6.2
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 }
Download response builder.
setFilename(string $filename='', bool $inline=false)
Set the filename for the download.
setForwardURL(string $forward_url=REFERRER)
{Sets redirect URL.Forward URL self }
getHeaders()
{Returns additional response headers.array}
OK response builder.
Definition: OkResponse.php:8
string $forward_url
Definition: Response.php:20
const REFERRER
Used in calls to forward() to specify the browser should be redirected to the referring page.
Definition: constants.php:37
elgg_is_empty($value)
Check if a value isn't empty, but allow 0 and '0'.
Definition: input.php:176
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
$inline
Definition: save.php:22