From aac9cf1fe09bc210349da25891954948db28ab17 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 7 Feb 2020 22:05:27 +0000 Subject: [PATCH] merge some self-contained bits from @sanmadjack's branch --- core/basepage.php | 14 ++++++++++++-- core/polyfills.php | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/basepage.php b/core/basepage.php index 95c5965b..05334b08 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -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) { diff --git a/core/polyfills.php b/core/polyfills.php index ae9125f6..65b0c278 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -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.