merge some self-contained bits from @sanmadjack's branch

This commit is contained in:
Shish 2020-02-07 22:05:27 +00:00
parent 45347279ce
commit aac9cf1fe0
2 changed files with 14 additions and 3 deletions

View file

@ -83,6 +83,9 @@ class BasePage
/** @var string */
private $file = null;
/** @var bool */
private $file_delete = false;
/** @var string */
private $filename = null;
@ -96,9 +99,10 @@ class BasePage
$this->data = $data;
}
public function set_file(string $file): void
public function set_file(string $file, bool $delete = false): void
{
$this->file = $file;
$this->file_delete = $delete;
}
/**
@ -353,7 +357,13 @@ class BasePage
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: " . $length);
stream_file($this->file, $start, $end);
try {
stream_file($this->file, $start, $end);
} finally {
if ($this->file_delete === true) {
unlink($this->file);
}
}
break;
case PageMode::REDIRECT:
if ($this->flash) {

View file

@ -156,12 +156,13 @@ function stream_file(string $file, int $start, int $end): void
try {
set_time_limit(0);
fseek($fp, $start);
$buffer = 1024 * 64;
$buffer = 1024 * 1024;
while (!feof($fp) && ($p = ftell($fp)) <= $end) {
if ($p + $buffer > $end) {
$buffer = $end - $p + 1;
}
echo fread($fp, $buffer);
if(!defined("UNITTEST")) @ob_flush();
flush();
// After flush, we can tell if the client browser has disconnected.