MediaWiki  1.23.8
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=array(), $sendErrors=true)
 Call this function used in preparation before streaming a file. More...
 
static stream ( $fname, $headers=array(), $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

◆ contentTypeFromPath()

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 151 of file StreamFile.php.

References $ext, $type, $wgFileExtensions, $wgTrivialMimeDetection, UploadBase\checkFileExtensionList(), global, list, and UploadBase\splitExtensions().

Referenced by FileBackendStore\__construct(), and prepareForStream().

◆ prepareForStream()

static StreamFile::prepareForStream (   $path,
  $info,
  $headers = array(),
  $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 81 of file StreamFile.php.

References $path, $type, as, contentTypeFromPath(), NOT_MODIFIED, READY_STREAM, TS_RFC2822, TS_UNIX, wfResetOutputBuffers(), and wfTimestamp().

Referenced by stream(), and FileBackendStore\streamFile().

◆ stream()

static StreamFile::stream (   $fname,
  $headers = array(),
  $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, $ok, $res, FileBackend\isStoragePath(), prepareForStream(), wfProfileIn(), wfProfileOut(), wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by MediaTransformOutput\streamFile().

Member Data Documentation

◆ NOT_MODIFIED

const StreamFile::NOT_MODIFIED = 2

Definition at line 28 of file StreamFile.php.

Referenced by prepareForStream(), and FileBackendStore\streamFile().

◆ READY_STREAM

const StreamFile::READY_STREAM = 1

Definition at line 27 of file StreamFile.php.

Referenced by prepareForStream(), and FileBackendStore\streamFile().


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