$files->send() method

Send the contents of the given filename to the current http connection

This function utilizes the $config->fileContentTypes to match file extension to content type headers and force-download state.

This function throws a WireException if the file can’t be sent for some reason. Set the throw option to false if you want it to instead return integer 0 when errors occur.

Usage

// basic usage
$int = $files->send($filename);

// usage with all arguments
$int = $files->send($filename, array $options = [], array $headers = []);

Arguments

NameType(s)Description
filenamestring, bool

Full path and filename to send or boolean false if provided in $options[data].

options (optional)array

Optional options to modify default behavior:

  • exit (bool): Halt program execution after file send (default=true).
  • partial (bool): Allow use of partial downloads via HTTP_RANGE requests? Since 3.0.131 (default=true)
  • forceDownload (bool|null): Whether file should force download, or null to let content-type header decide (default=null).
  • downloadFilename (string): Filename you want the download to show on user’s computer, or omit to use existing (default='').
  • headers (array): The $headers argument to this method can also be provided as an option right here (default=[]). Since 3.0.131.
  • data (string): String of data to send rather than file, $filename argument must be false (default=''). Since 3.0.132.
  • limitPath (string|bool): Prefix disk path $filename must be within, false to disable, true for site/assets (default=false). Since 3.0.169.
  • throw (bool): Throw exceptions on error? When false, it will instead return integer 0 on errors (default=true). Since 3.0.169.
headers (optional)array

Optional headers that are sent, below are the defaults:

  • pragma: public
  • expires: 0
  • cache-control: must-revalidate, post-check=0, pre-check=0
  • content-type: {content-type} (replaced with actual content type)
  • content-transfer-encoding: binary
  • content-length: {filesize} (replaced with actual filesize)
  • To remove a header completely, make its value NULL.
  • If preferred, the above headers can be specified in $options[headers] instead.

Return value

int

Returns bytes sent, only if exit option is false (since 3.0.169)

Exceptions

Method can throw exceptions on error:

  • WireException

See Also


$files methods and properties

API reference based on ProcessWire core version 3.0.185

Twitter updates

  • ProcessWire 3.0.190 has 15 commits relative to 3.0.189 and contains a mixture of issue resolutions and feature additions. We’ll review these below, in addition to updates for the PageAutosave and ProFields Table modules— More
    3 December 2021
  • Great video by @jlahijani that demonstrates his ProcessWire page builder using ProFields Repeater Matrix, the new Page Autosave + Live Preview module and Uikit 3— youtube.com/watch?v=Rb5kiU…
    13 November 2021
  • More development on page automatic save this week, plus the addition of live preview— More
    12 November 2021

Latest news

  • ProcessWire Weekly #395
    In the 395th issue of ProcessWire Weekly we'll cover the latest core updates, check out the MJLM to HTML module, and more. Read on!
    Weekly.pw / 4 December 2021
  • ProcessWire 3.0.190 core updates
    ProcessWire 3.0.190 has 15 commits relative to 3.0.189 and contains a mixture of issue resolutions and feature additions. This post covers them all, in addition to updates for the PageAutosave and ProFields Table modules.
    Blog / 3 December 2021
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.