ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 {
40  public const X_SENDFILE = 'X-Sendfile';
44  public const X_SENDFILE_TEMPORARY = 'X-Sendfile-Temporary';
45 
46 
52  public function __construct(private Services $httpService)
53  {
54  }
55 
56 
60  public function doesFileExists(string $path_to_file): bool
61  {
62  return is_readable($path_to_file);
63  }
64 
65 
69  public function prepare(string $path_to_file, ?FileStream $possible_stream): bool
70  {
71  // Nothing has to be done here
72  return true;
73  }
74 
75 
79  public function deliver(string $path_to_file, bool $file_marked_to_delete): void
80  {
81  $delivery = function () use ($path_to_file): void {
82  $response = $this->httpService->response()
83  ->withHeader(self::X_SENDFILE, realpath($path_to_file));
84  $this->httpService->saveResponse($response);
85  $this->httpService->sendResponse();
86  };
87 
88  if ($file_marked_to_delete) {
89  $this->sendFileUnbufferedUsingHeaders($delivery);
90  } else {
91  $delivery();
92  }
93  }
94 
95 
99  public function supportsInlineDelivery(): bool
100  {
101  return true;
102  }
103 
104 
108  public function supportsAttachmentDelivery(): bool
109  {
110  return true;
111  }
112 
113 
117  public function supportsStreaming(): bool
118  {
119  return true;
120  }
121 
122 
126  public function handleFileDeletion(string $path_to_file): bool
127  {
128  return unlink($path_to_file);
129  }
130 }
$response
Definition: xapitoken.php:93
handleFileDeletion(string $path_to_file)
bool
Definition: XSendfile.php:126
prepare(string $path_to_file, ?FileStream $possible_stream)
Definition: XSendfile.php:69
__construct(private Services $httpService)
PHP constructor.
Definition: XSendfile.php:52
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:79
The base interface for all filesystem streams.
Definition: FileStream.php:31