mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°5122 - Update libs to new PHP requirements
This commit is contained in:
@@ -34,6 +34,7 @@ class BinaryFileResponse extends Response
|
||||
protected $offset = 0;
|
||||
protected $maxlen = -1;
|
||||
protected $deleteFileAfterSend = false;
|
||||
protected $chunkSize = 8 * 1024;
|
||||
|
||||
/**
|
||||
* @param \SplFileInfo|string $file The file to stream
|
||||
@@ -125,6 +126,22 @@ class BinaryFileResponse extends Response
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response stream chunk size.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setChunkSize(int $chunkSize): self
|
||||
{
|
||||
if ($chunkSize < 1 || $chunkSize > \PHP_INT_MAX) {
|
||||
throw new \LogicException('The chunk size of a BinaryFileResponse cannot be less than 1 or greater than PHP_INT_MAX.');
|
||||
}
|
||||
|
||||
$this->chunkSize = $chunkSize;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically sets the Last-Modified header according the file modification date.
|
||||
*
|
||||
@@ -306,7 +323,23 @@ class BinaryFileResponse extends Response
|
||||
$out = fopen('php://output', 'w');
|
||||
$file = fopen($this->file->getPathname(), 'r');
|
||||
|
||||
stream_copy_to_stream($file, $out, $this->maxlen, $this->offset);
|
||||
ignore_user_abort(true);
|
||||
|
||||
if (0 !== $this->offset) {
|
||||
fseek($file, $this->offset);
|
||||
}
|
||||
|
||||
$length = $this->maxlen;
|
||||
while ($length && !feof($file)) {
|
||||
$read = ($length > $this->chunkSize) ? $this->chunkSize : $length;
|
||||
$length -= $read;
|
||||
|
||||
stream_copy_to_stream($file, $out, $read);
|
||||
|
||||
if (connection_aborted()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($out);
|
||||
fclose($file);
|
||||
|
||||
Reference in New Issue
Block a user