Download extends Component uses File
Download component
Simplifies the file download/stream process by setting the appropriate headers
Table of Contents
Properties
| $components | |
| $helpers | |
| $models | |
| $allowed_paths | |
| $content_type | |
| $encoding |
Methods
| __construct() | Initializes the Download object, sets the default encoding |
| addAllowedPath() | Adds a new path to the whitelist of allowed paths |
| downloadData() | Forces download of the given data |
| downloadFile() | Forces download of a file |
| getAllowedPaths() | Returns an array of all allowed paths |
| removeAllowedPath() | Removes an existing path from the whitelist of allowed paths |
| setAllowedPaths() | Sets an array of paths, as the whitelist of allowed paths |
| setContentType() | Overrides the currently set Content Type for this file |
| setEncoding() | Overrides the currently set file encoding |
| streamData() | Streams the given data to the standard output stream (e.g. a browser) |
| streamFile() | Streams a file out to the standard output stream (e.g. a browser) |
| output() | Sends the file to the output stream and ends the request |
| setHeader() | Sets a header |
Properties
$components
protected
mixed
$components
$helpers
protected
mixed
$helpers
$models
protected
mixed
$models
$allowed_paths
private
array<string|int, mixed>
$allowed_paths
= [CACHEDIR]
A list of directories that are allowed for reading and writing
$content_type
private
array<string|int, mixed>
$content_type
An array of content types to set when deliverying the file
$encoding
private
string
$encoding
The encoding used to deliver the file
Methods
__construct()
Initializes the Download object, sets the default encoding
public
__construct([string $encoding = 'binary' ]) : mixed
Parameters
- $encoding : string = 'binary'
-
The download encoding (optional, default binary)
addAllowedPath()
Adds a new path to the whitelist of allowed paths
public
addAllowedPath(mixed $path) : mixed
Parameters
- $path : mixed
downloadData()
Forces download of the given data
public
downloadData(string $file_name, string $data) : mixed
Parameters
- $file_name : string
-
The name of the file to be downloaded
- $data : string
-
The data to be downloaded
downloadFile()
Forces download of a file
public
downloadFile(string $file[, string $file_name = null ][, string $send_mode = 'file' ]) : mixed
Parameters
- $file : string
-
The full path to the file name to be downloaded
- $file_name : string = null
-
The name to give the file being downloaded (defaults to the real file name)
- $send_mode : string = 'file'
-
The send mode for the file (file to send normally, xsendfile to send through mod_xsendfile)
getAllowedPaths()
Returns an array of all allowed paths
public
getAllowedPaths() : array<string|int, mixed>
Return values
array<string|int, mixed>removeAllowedPath()
Removes an existing path from the whitelist of allowed paths
public
removeAllowedPath(mixed $path) : mixed
Parameters
- $path : mixed
setAllowedPaths()
Sets an array of paths, as the whitelist of allowed paths
public
setAllowedPaths(array<string|int, mixed> $paths) : mixed
Parameters
- $paths : array<string|int, mixed>
setContentType()
Overrides the currently set Content Type for this file
public
setContentType(mixed $content_type) : mixed
Parameters
- $content_type : mixed
-
A numerically indexed array of content types to set, or a string containing the content type to set
setEncoding()
Overrides the currently set file encoding
public
setEncoding(string $encoding) : mixed
Parameters
- $encoding : string
-
The file encoding to set for all subsequent streams or downloads
streamData()
Streams the given data to the standard output stream (e.g. a browser)
public
streamData(string $file_name, string $data) : mixed
Parameters
- $file_name : string
-
The name of the file to be streamed
- $data : string
-
The data to be streamed
streamFile()
Streams a file out to the standard output stream (e.g. a browser)
public
streamFile(string $file[, string $file_name = null ][, string $send_mode = 'file' ]) : mixed
Parameters
- $file : string
-
The full path to the file name to be streamed
- $file_name : string = null
-
The name to give the file being streamed (defaults to the real file name)
- $send_mode : string = 'file'
-
The send mode for the file (file to send normally, xsendfile to send through mod_xsendfile)
output()
Sends the file to the output stream and ends the request
private
output(string $file, string $type) : mixed
Parameters
- $file : string
-
The file path or data to output
- $type : string
-
The type of $file (data, file, or xsendfile)
setHeader()
Sets a header
private
setHeader(string $field, string $value) : mixed
Parameters
- $field : string
-
The name of the header to set
- $value : string
-
The value of the header to set