diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 316bfea610c4..91fc52dd04a9 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -430,10 +430,14 @@ public function readfile($path) { \OCP\Util::writeLog('DEBUG', 'readfile: before loop', \OCP\Util::DEBUG); while (!feof($handle)) { echo fread($handle, $chunkSize); - flush(); + // keep the last flush for after fclose + if (!feof($handle)) { + flush(); + } } \OCP\Util::writeLog('DEBUG', 'readfile: after loop, preparing to fclose', \OCP\Util::DEBUG); fclose($handle); + flush(); \OCP\Util::writeLog('DEBUG', 'readfile: fclose called', \OCP\Util::DEBUG); $size = $this->filesize($path); \OCP\Util::writeLog('DEBUG', 'readfile: got filesize: ' . $size, \OCP\Util::DEBUG); @@ -468,12 +472,16 @@ public function readfilePart($path, $from, $to) { $len = $chunkSize; } echo fread($handle, $len); - flush(); + // keep the last flush for after fclose + if (!feof($handle)) { + flush(); + } } \OCP\Util::writeLog('DEBUG', 'readfilePart: after loop', \OCP\Util::DEBUG); $size = ftell($handle) - $from; \OCP\Util::writeLog('DEBUG', 'readfilePart: preparing to fclose', \OCP\Util::DEBUG); fclose($handle); + flush(); \OCP\Util::writeLog('DEBUG', 'readfile: fclose called', \OCP\Util::DEBUG); return $size; }