19 declare(strict_types=1);
46 $this->httpService = $httpState;
55 return is_readable($path_to_file);
62 public function prepare(
string $path_to_file): bool
72 public function deliver(
string $path_to_file,
bool $file_marked_to_delete): void
74 $file = $path_to_file;
75 $fp = @fopen($file,
'rb');
78 $response = $this->httpService->response()->withStatus(404);
79 $this->httpService->saveResponse(
$response);
83 $size = filesize($file);
99 $response = $this->httpService->response()->withHeader(
"Accept-Ranges",
"0-$length");
100 $this->httpService->saveResponse(
$response);
101 $server = $this->httpService->request()->getServerParams();
105 if (isset(
$server[
'HTTP_RANGE'])) {
110 [, $range] = explode(
'=',
$server[
'HTTP_RANGE'], 2);
112 if (strpos($range,
',') !==
false) {
117 $this->httpService->saveResponse(
$response);
126 if ($range[0] ===
'-') {
128 $c_start = $size - substr($range, 1);
130 $range = explode(
'-', $range);
131 $c_start = $range[0];
132 $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
138 $c_end = ($c_end > $end) ? $end : $c_end;
140 if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
143 $this->httpService->saveResponse(
$response);
150 $length = $end - $start + 1;
151 fseek($fp, (
int) $start);
153 $response = $this->httpService->response()->withStatus(206);
155 $this->httpService->saveResponse(
$response);
161 $this->httpService->saveResponse(
$response);
164 $this->httpService->sendResponse();
168 while (!feof($fp) && ($p = ftell($fp)) <= $end) {
169 if ($p + $buffer > $end) {
172 $buffer = $end - $p + 1;
176 echo fread($fp, $buffer);
214 $this->httpService->sendResponse();
224 return unlink($path_to_file);
ILIAS HTTP Services $httpService
handleFileDeletion(string $path_to_file)
bool
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Services $httpState)
PHP constructor.
Interface ilFileDeliveryType.
doesFileExists(string $path_to_file)
deliver(string $path_to_file, bool $file_marked_to_delete)
absolute path to fileThis is needed at this point for header-based delivery methodsvoid ...
prepare(string $path_to_file)
bool
supportsAttachmentDelivery()