Oihana PHP System

applyContentHeaders.php

Table of Contents

Functions

applyContentHeaders()  : ResponseInterface
Applies the download content headers (`Content-Type`, `Content-Length`, `Content-Disposition`) to a PSR-7 response, toggled by {@see FileResponseOption}.

Functions

applyContentHeaders()

Applies the download content headers (`Content-Type`, `Content-Length`, `Content-Disposition`) to a PSR-7 response, toggled by {@see FileResponseOption}.

applyContentHeaders(ResponseInterface $response, string $file[, string|null $contentType = null ][, array<string|int, mixed> $options = [] ][, bool $defaultOn = true ]) : ResponseInterface

Shared by the file/archive/image/encryption response helpers so the header logic lives in one place.

Parameters
$response : ResponseInterface

The PSR-7 response to decorate.

$file : string

Path of the file whose size/MIME type back the headers (must exist).

$contentType : string|null = null

The Content-Type to advertise; when null, mime_content_type($file) is used.

$options : array<string|int, mixed> = []

Header switches keyed by FileResponseOption:

  • useContentType (bool) emit Content-Type.
  • useContentLength (bool) emit Content-Length (file size).
  • useContentDisposition (bool) emit Content-Disposition.
  • contentDisposition (string) value to use (defaults to attachment; filename=<basename>).
$defaultOn : bool = true

Default state of the three switches when absent from $options.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
ResponseInterface

The response with the requested headers applied.

On this page

Search results