From 7d87ae2b0e6d3218f23d879f8e67d3f711040e62 Mon Sep 17 00:00:00 2001 From: Sebastian Kostka Date: Sun, 9 Apr 2017 10:13:39 +0200 Subject: [PATCH] Work around file size issues at 32 Bit systems Replace stream_copy_to_stream with a chunked process, to handle file sizes hat do not fit into an integer. Implementation according to http://php.net/manual/en/function.stream-copy-to-stream.php#98119, proposed and implemented by https://github.com/rikmeijer in https://github.com/nextcloud/server/issues/1707#issuecomment-291835214. --- lib/Sapi.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Sapi.php b/lib/Sapi.php index dd49913..4101f82 100644 --- a/lib/Sapi.php +++ b/lib/Sapi.php @@ -88,7 +88,9 @@ static function sendResponse(ResponseInterface $response) { if ($contentLength !== null) { $output = fopen('php://output', 'wb'); if (is_resource($body) && get_resource_type($body) == 'stream') { - stream_copy_to_stream($body, $output, (int)$contentLength); + while (!feof($body)) { + fwrite($output,fread($body,8192)); + } } else { fwrite($output, $body, (int)$contentLength); }