MediaWiki  1.27.2
StreamFile Class Reference

Functions related to the output of file content. More...

Static Public Member Functions

static contentTypeFromPath ($filename, $safe=true)
 Determine the file type of a file based on the path. More...
 
static prepareForStream ($path, $info, $headers=[], $sendErrors=true)
 Call this function used in preparation before streaming a file. More...
 
static stream ($fname, $headers=[], $sendErrors=true)
 Stream a file to the browser, adding all the headings and fun stuff. More...
 

Public Attributes

const NOT_MODIFIED = 2
 
const READY_STREAM = 1
 

Detailed Description

Functions related to the output of file content.

Definition at line 26 of file StreamFile.php.

Member Function Documentation

static StreamFile::contentTypeFromPath (   $filename,
  $safe = true 
)
static

Determine the file type of a file based on the path.

Parameters
string$filenameStorage path or file system path
bool$safeWhether to do retroactive upload blacklist checks
Returns
null|string

Definition at line 146 of file StreamFile.php.

References $ext, $type, $wgCheckFileExtensions, $wgFileBlacklist, $wgFileExtensions, $wgMimeTypeBlacklist, $wgStrictFileExtensions, $wgTrivialMimeDetection, $wgVerifyMimeType, UploadBase\checkFileExtensionList(), global, list, MimeMagic\singleton(), and UploadBase\splitExtensions().

Referenced by FileBackendDBRepoWrapper\streamFile().

static StreamFile::prepareForStream (   $path,
  $info,
  $headers = [],
  $sendErrors = true 
)
static

Call this function used in preparation before streaming a file.

This function does the following: (a) sends Last-Modified, Content-type, and Content-Disposition headers (b) cancels any PHP output buffering and automatic gzipping of output (c) sends Content-Length header based on HTTP_IF_MODIFIED_SINCE check

Parameters
string$pathStorage path or file system path
array | bool$infoFile stat info with 'mtime' and 'size' fields
array$headersAdditional headers to send
bool$sendErrorsSend error messages if errors occur (like 404)
Returns
int|bool READY_STREAM, NOT_MODIFIED, or false on failure

Definition at line 76 of file StreamFile.php.

References $path, $type, as, HttpStatus\header(), TS_RFC2822, TS_UNIX, wfResetOutputBuffers(), and wfTimestamp().

Referenced by FileBackendStore\streamFile().

static StreamFile::stream (   $fname,
  $headers = [],
  $sendErrors = true 
)
static

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.

Parameters
string$fnameFull name and path of the file to stream
array$headersAny additional headers to send
bool$sendErrorsSend error messages if errors occur (like 404)
Exceptions
MWException
Returns
bool Success

Definition at line 41 of file StreamFile.php.

References $fname, $res, and FileBackend\isStoragePath().

Referenced by MediaTransformOutput\streamFileWithStatus().

Member Data Documentation

const StreamFile::NOT_MODIFIED = 2

Definition at line 28 of file StreamFile.php.

Referenced by FileBackendStore\streamFile().

const StreamFile::READY_STREAM = 1

Definition at line 27 of file StreamFile.php.

Referenced by FileBackendStore\streamFile().


The documentation for this class was generated from the following file: