merge some self-contained bits from @sanmadjack's branch
This commit is contained in:
parent
45347279ce
commit
aac9cf1fe0
@ -83,6 +83,9 @@ class BasePage
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private $file = null;
|
private $file = null;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
private $file_delete = false;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $filename = null;
|
private $filename = null;
|
||||||
|
|
||||||
@ -96,9 +99,10 @@ class BasePage
|
|||||||
$this->data = $data;
|
$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 = $file;
|
||||||
|
$this->file_delete = $delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,7 +357,13 @@ class BasePage
|
|||||||
header("Content-Range: bytes $start-$end/$size");
|
header("Content-Range: bytes $start-$end/$size");
|
||||||
header("Content-Length: " . $length);
|
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;
|
break;
|
||||||
case PageMode::REDIRECT:
|
case PageMode::REDIRECT:
|
||||||
if ($this->flash) {
|
if ($this->flash) {
|
||||||
|
@ -156,12 +156,13 @@ function stream_file(string $file, int $start, int $end): void
|
|||||||
try {
|
try {
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
fseek($fp, $start);
|
fseek($fp, $start);
|
||||||
$buffer = 1024 * 64;
|
$buffer = 1024 * 1024;
|
||||||
while (!feof($fp) && ($p = ftell($fp)) <= $end) {
|
while (!feof($fp) && ($p = ftell($fp)) <= $end) {
|
||||||
if ($p + $buffer > $end) {
|
if ($p + $buffer > $end) {
|
||||||
$buffer = $end - $p + 1;
|
$buffer = $end - $p + 1;
|
||||||
}
|
}
|
||||||
echo fread($fp, $buffer);
|
echo fread($fp, $buffer);
|
||||||
|
if(!defined("UNITTEST")) @ob_flush();
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
// After flush, we can tell if the client browser has disconnected.
|
// After flush, we can tell if the client browser has disconnected.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user