ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
XSendfile.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
34 final class XSendfile implements ilFileDeliveryType
35 {
37  public const X_SENDFILE = 'X-Sendfile';
38  public const X_SENDFILE_TEMPORARY = 'X-Sendfile-Temporary';
39  private \ILIAS\HTTP\Services $httpService;
40 
41 
48  public function __construct(Services $httpState)
49  {
50  $this->httpService = $httpState;
51  }
52 
53 
57  public function doesFileExists(string $path_to_file): bool
58  {
59  return is_readable($path_to_file);
60  }
61 
62 
66  public function prepare(string $path_to_file, ?FileStream $possible_stream): bool
67  {
68  // Nothing has to be done here
69  return true;
70  }
71 
72 
76  public function deliver(string $path_to_file, bool $file_marked_to_delete): void
77  {
78  $response = $this->httpService->response()
79  ->withHeader(self::X_SENDFILE, realpath($path_to_file));
80  $this->httpService->saveResponse($response);
81  $this->httpService->sendResponse();
82  }
83 
84 
88  public function supportsInlineDelivery(): bool
89  {
90  return true;
91  }
92 
93 
97  public function supportsAttachmentDelivery(): bool
98  {
99  return true;
100  }
101 
102 
106  public function supportsStreaming(): bool
107  {
108  return true;
109  }
110 
111 
115  public function handleFileDeletion(string $path_to_file): bool
116  {
117  return unlink($path_to_file);
118  }
119 }
$response
Definition: xapitoken.php:90
handleFileDeletion(string $path_to_file)
bool
Definition: XSendfile.php:115
__construct(Services $httpState)
PHP constructor.
Definition: XSendfile.php:48
prepare(string $path_to_file, ?FileStream $possible_stream)
Definition: XSendfile.php:66
deliver(string $path_to_file, bool $file_marked_to_delete)
absolute path to fileThis is needed at this point for header-based delivery methodsvoid ...
Definition: XSendfile.php:76
The base interface for all filesystem streams.
Definition: FileStream.php:31