/** * Stream a file to the browser, adding all the headings and fun stuff. * Headers sent include: Content-type, Content-Length, Last-Modified, * and Content-Disposition. * * @param string $fname Full name and path of the file to stream * @param array $headers Any additional headers to send if the file exists * @param bool $sendErrors Send error messages if errors occur (like 404) * @param array $optHeaders HTTP request header map (e.g. "range") (use lowercase keys) * @param integer $flags Bitfield of STREAM_* constants * @throws MWException * @return bool Success */ public static function stream($fname, $headers = [], $sendErrors = true, $optHeaders = [], $flags = 0) { if (FileBackend::isStoragePath($fname)) { // sanity throw new InvalidArgumentException(__FUNCTION__ . " given storage path '{$fname}'."); } $streamer = new HTTPFileStreamer($fname, ['obResetFunc' => 'wfResetOutputBuffers', 'streamMimeFunc' => [__CLASS__, 'contentTypeFromPath']]); return $streamer->stream($headers, $sendErrors, $optHeaders, $flags); }
/** * @see FileBackendStore::streamFile() * @param array $params * @return StatusValue */ protected function doStreamFile(array $params) { $status = $this->newStatus(); $flags = 0; $flags |= !empty($params['headless']) ? HTTPFileStreamer::STREAM_HEADLESS : 0; $flags |= !empty($params['allowOB']) ? HTTPFileStreamer::STREAM_ALLOW_OB : 0; $fsFile = $this->getLocalReference($params); if ($fsFile) { $streamer = new HTTPFileStreamer($fsFile->getPath(), ['obResetFunc' => $this->obResetFunc, 'streamMimeFunc' => $this->streamMimeFunc]); $res = $streamer->stream($params['headers'], true, $params['options'], $flags); } else { $res = false; HTTPFileStreamer::send404Message($params['src'], $flags); } if (!$res) { $status->fatal('backend-fail-stream', $params['src']); } return $status; }