ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
XSendfile.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 require_once('./Services/FileDelivery/interfaces/int.ilFileDeliveryType.php');
9 
17 final class XSendfile implements ilFileDeliveryType
18 {
20  const X_SENDFILE = 'X-Sendfile';
21  const X_SENDFILE_TEMPORARY = 'X-Sendfile-Temporary';
25  private $httpService;
26 
27 
34  public function __construct(GlobalHttpState $httpState)
35  {
36  $this->httpService = $httpState;
37  }
38 
39 
43  public function doesFileExists($path_to_file)
44  {
45  return is_readable($path_to_file);
46  }
47 
48 
52  public function prepare($path_to_file)
53  {
54  // Nothing has to be done here
55  return true;
56  }
57 
58 
62  public function deliver($path_to_file, $file_marked_to_delete)
63  {
64  $delivery = function () use ($path_to_file) {
65  $response = $this->httpService->response()
66  ->withHeader(self::X_SENDFILE, realpath($path_to_file));
67  $this->httpService->saveResponse($response);
68  $this->httpService->sendResponse();
69  };
70 
71  if ($file_marked_to_delete) {
72  $this->sendFileUnbufferedUsingHeaders($delivery);
73  } else {
74  $delivery();
75  }
76 
77  return true;
78  }
79 
80 
84  public function supportsInlineDelivery()
85  {
86  return true;
87  }
88 
89 
93  public function supportsAttachmentDelivery()
94  {
95  return true;
96  }
97 
98 
102  public function supportsStreaming()
103  {
104  return true;
105  }
106 
107 
111  public function handleFileDeletion($path_to_file)
112  {
113  unlink($path_to_file);
114  }
115 }
Interface GlobalHttpState.
deliver($path_to_file, $file_marked_to_delete)
absolute path to fileThis is needed at this point for header-based delivery methodsbool ...
Definition: XSendfile.php:62
$response
__construct(GlobalHttpState $httpState)
PHP constructor.
Definition: XSendfile.php:34