/** * Reads out a file, and echos the content to the client. * * @param File $file File object * @param array $range The range to read out of the file. * @return bool True is whole file is echoed successfully or false if client connection is lost in between */ protected function _sendFile($file, $range) { $compress = $this->outputCompressed(); $file->open('rb'); $end = $start = false; if ($range) { list($start, $end) = $range; } if ($start !== false) { $file->offset($start); } $bufferSize = 8192; set_time_limit(0); session_write_close(); while (!feof($file->handle)) { if (!$this->_isActive()) { $file->close(); return false; } $offset = $file->offset(); if ($end && $offset >= $end) { break; } if ($end && $offset + $bufferSize >= $end) { $bufferSize = $end - $offset + 1; } echo fread($file->handle, $bufferSize); if (!$compress) { $this->_flushBuffer(); } } $file->close(); return true; }