Index

FileResponse

MMO\edms\server · 1 symbol · generated 5 Oct 2026

class

FileResponse

FileResponse.php:19

A stored file, sent as it is read: a download can be bigger than PHP's memory, which StreamResponse::render reads the whole stream into.

class MMO\edms\server\FileResponse extends MMO\core\server\StreamResponse
Namespace
MMO\edms\server
Extends
StreamResponse
It answers a `Range` request with the part asked for (206: a download resumed, a video sought), a request that already has this version (`If-None-Match`) with nothing (304), and lets the browser show the file itself (`inline`) only for the types that cannot run a script in the site's pages ([`INLINE_TYPES`](https://mcp.mmoframework.fr/documentation/mmo.edms/php/server/FileResponse.md#fileresponse-inline-types)).
return FileResponse::FromFile($file, $route->getRequest(), inline: true);

Index

CHUNK_SIZEthe size of what is read, then sent, at a time
INLINE_TYPESthe types a browser may show rather than save: an html page or an svg shown in the site would be the site's
handle
hasBody
length
offset
ContentDisposition($name, $inline) staticA Content-Disposition header for a file named $name: an ascii name for old clients, and the real one as RFC 6266 has it (filename*), so a quote or an accent in a name cannot break the header.
FromFile($file, $request, $inline, $name, $headers) staticThe response sending $file, as $request asks for it (a part of it, or nothing if it has it already)
getContent()
Header($request, $name) static
IsInline($mime) static
loopChunks()
ParseRange($range, $size) staticThe part of a file of $size bytes a Range header asks for: one range of bytes (several are answered whole)
render($opts)Send the bytes, a chunk at a time, as they are read: nothing is left to return
__construct($handle, $offset, $length, $code, $reason, $headers)

Constants2

CHUNK_SIZE

the size of what is read, then sent, at a time

const CHUNK_SIZE = 1048576

INLINE_TYPES

the types a browser may show rather than save: an html page or an svg shown in the site would be the site's

const INLINE_TYPES = […15 items]

Properties4

handle

protected $handle = null

hasBody

protected bool $hasBody = true
Type
bool

length

protected int $length = 0
Type
int

offset

protected int $offset = 0
Type
int

Methods9

ContentDisposition($name, $inline)

staticFileResponse.php:114

A Content-Disposition header for a file named $name: an ascii name for old clients, and the real one as RFC 6266 has it (filename*), so a quote or an accent in a name cannot break the header.

static function ContentDisposition(string $name, bool $inline = false): string
$namestring
$inline = falseboolif true, the browser shows the file rather than saving it
returnsstring
FileResponse::ContentDisposition('Été "2025".pdf'); // attachment; filename="_t_ _2025_.pdf"; filename*=UTF-8''%C3%89t%C3%A9%20%222025%22.pdf

FromFile($file, $request, $inline, $name, $headers)

staticFileResponse.php:54

The response sending $file, as $request asks for it (a part of it, or nothing if it has it already)

static function FromFile( MMO\edms\entities\File $file, ?Psr\Http\Message\RequestInterface $request = null, bool $inline = false, ?string $name = null, array $headers = [] ): self
$fileFile
$request = nullnull | RequestInterface
$inline = falseboolif true, the browser shows the file rather than saving it, when its type allows it (IsInline)
$name = nullnull | stringthe name of the file saved, its own by default
$headers = []array
returnsself

Header($request, $name)

staticFileResponse.php:99
static function Header(Psr\Http\Message\RequestInterface $request, string $name): string
$requestRequestInterface
$namestring
returnsstringa header of $request: under its name, or as php's $_SERVER has it -- the way a request of the server keeps them (Range is HTTP_RANGE)
FileResponse::Header($route->getRequest(), 'X-CSRF-Token');

IsInline($mime)

staticFileResponse.php:104
static function IsInline(string $mime): bool
$mimestring
returnsbooltrue if a file of the media type $mime can be shown by the browser in the site's pages

ParseRange($range, $size)

staticFileResponse.php:128

The part of a file of $size bytes a Range header asks for: one range of bytes (several are answered whole)

static function ParseRange(string $range, int $size): array|false|null
$rangestring
$sizeint
returnsarray | false | nullint, 1: int}|false|null [first byte, last byte], null for the whole file, false if the range is outside it
FileResponse::ParseRange('bytes=0-99', 1000); // [0, 99]FileResponse::ParseRange('bytes=-100', 1000); // [900, 999]

render($opts)

FileResponse.php:145

Send the bytes, a chunk at a time, as they are read: nothing is left to return

function render(array $opts = []): string
$opts = []array
returnsstring

__construct($handle, $offset, $length, $code, $reason, $headers)

FileResponse.php:41
function __construct( $handle, int $offset, int $length, int $code = 200, string $reason = '', array $headers = [] )
$handlethe bytes, to read
$offsetintwhere the part sent starts
$lengthintthe size of the part sent
$code = 200int
$reason = ''string
$headers = []array
Inherited members (74)
PropertiesDeclared byDescription
headersaMessage
ikeysaMessage
ListenersaMessage
protocolaMessage
statusCodeaResponse
statusTextaResponse
stoppedaResponse
streamStreamResponse
MethodsDeclared byDescription
addHeader($name, $value)aMessageAppend a value to a header, keeping any value(s) already set (as opposed to setHeader, which replaces).
AddListener($handler, $order)aMessageRegister a listener directly (as opposed to ConnectListeners's attribute-based discovery).
ConnectListeners($obj)aMessageScan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class.
debugName()aResponse
DisconnectListeners($obj)aMessageUndo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class.
dispatch()aMessageInvoke every GetListeners listener with $this.
File($filename, $headers, $clientFilename)StreamResponseCreate a Stream response using a local file
getBody()StreamResponseGets the body of the message.
getCharset()aMessage
getContentExtension()aMessage
getContentType($single)StreamResponsePrefers an explicitly-set 'Content-Type' header (tWithHeaders::getContentType); falls back to the stream's own detected type (Stream::getContentType) when no header was set and the stream…
getExitCode()aResponse
getHeader($name)aMessageRetrieves a message header value by the given case-insensitive name.
getHeaderLine($name)aMessageRetrieves a comma-separated string of the values for a single header.
getHeaders()aMessageRetrieves all message header values.
GetListeners()aMessageCollect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep …
getOrigin()aMessageGet origin of the request by looking at 'Origin', then 'Referer', then 'Sender' in the request's headers.
getParsedBody()StreamResponseGet response body decoded.
getProtocolVersion()aMessageRetrieves the HTTP protocol version as a string.
getReasonPhrase()aResponseGets the response reason phrase associated with the status code.
getRedirect()aResponse
getStatusCode()aResponseGets the response status code.
getUserAgent()aMessage
hasHeader($name)aMessageChecks if a header exists by the given case-insensitive name.
HasListener($handler)aMessage
isHTML()aMessage
isIe()aMessage
isIphone()aMessage
isJSON()aMessage
isMac()aMessage
isMobile()aMessage
isOk()aResponse
isPropagationStopped()aResponse
isWindows()aMessage
JSON($filename, $clientFilename)StreamResponseCreate a Stream response for a local JSON file (attachment, must-revalidate caching).
lock()StreamResponseClose the underlying stream, releasing its resource.
logEvent($event)StreamResponse
output()StreamResponseSend the stream as it is read, a chunk at a time: from its start when it can seek, as render reads it.
RemoveListener($handler)aMessageRemove the last added handler from the listeners.
Send($args)aMessageConstruct a new instance of this class with $args, then dispatch it to every listener.
setCacheControl($cache, $pragma)aMessageSet the Cache-Control header (and, optionally, the legacy Pragma header alongside it).
setContentType($type, $charset)aMessageSet the Content-Type header, appending a charset parameter (unless $charset is null/empty).
setExpires($time)aMessageSet the Expires header from a unix timestamp, formatted as an RFC 7231 HTTP-date.
setHeader($name, $value)aMessageSet header, replacing any previous value(s) for the same (case-insensitively matched) header name.
SetListenerOrder($handler, $order)aMessageChange the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here).
setRedirect($url, $status)aResponseSet a redirection call send() to actually redirect
setRequireAuth($realm, $type)aResponseSet redirection to a login/password inputbox call send() to actually redirect
setStatus($code, $reason)aResponse
stopPropagation()aResponsePrevent any remaining listener in the current dispatch chain from being called.
unsetHeader($name)aMessageRemove a header entirely.
withAddedHeader($name, $value)aMessageReturn an instance with the specified header appended with the given value.
withBody($body)StreamResponseReturn an instance with the specified message body.
withCacheControl($cache, $pragma)aMessageSet cache control of a clone.
withContentType($type, $charset)aMessageSet content type of a clone.
withExpires($time)aMessageSet cache expire date of a clone.
withHeader($name, $value)aMessageReturn an instance with the provided value replacing the specified header.
withHeaders($headers, $reset)aMessageReturn a clone with every header in $headers set (through tWithHeaders::setHeader, so each value replaces any existing one for the same header name).
withoutHeader($name)aMessageReturn an instance without the specified header.
withParsedBody($data)StreamResponse
withProtocolVersion($version)aMessageReturn an instance with the specified HTTP protocol version.
withRedirect($url, $status)aResponseSet a redirection of a clone call send() to actually redirect
withRequireAuth($realm, $type)aResponseSet redirection to a login/password inputbox of a clone call send() to actually redirect
withStatus($code, $reasonPhrase)aResponseReturn an instance with the specified status code and, optionally, reason phrase.
Zip($filename, $headers, $clientFilename)StreamResponseCreate a Stream response for a local file, forced to the 'zip' content type (File for the rest).
__clone()aResponseA cloned event starts fresh: propagation is never considered stopped on the clone, even if it was on the original instance.
__toString()aResponse