From bfb5962784090b0d94dc8b33def4edc223e6fa93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 15 Apr 2021 15:32:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Http/File.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/HttpServer/Http/File.php b/HttpServer/Http/File.php index bd1f3241..15608e70 100644 --- a/HttpServer/Http/File.php +++ b/HttpServer/Http/File.php @@ -61,6 +61,38 @@ class File return $this->newName; } + + /** + * @return string + */ + public function getContent(): string + { + $open = fopen('php://temp', 'r'); + + $limit = 1024000; + + $stat = fstat($open); + + $sleep = $offset = 0; + + $content = ''; + while ($file = fread($open, $limit)) { + fseek($open, $offset); + + $content .= $file; + if ($sleep > 0) { + sleep($sleep); + } + if ($offset >= $stat['size']) { + break; + } + $offset += $limit; + } + + return $content; + } + + /** * @return string */