jResponseBinary
extends jResponse
in package
Response use to send a binary file to the browser.
It sends the content of a file (its path into $filename) or a custom content (set into $content). The downloaded content can be displayed directly into the browser (if it can display it), or you can force the browser to save it into a file, on the disk of the user. See $doDownload. You can indicate the name of the saved file into $outputFileName.
Tags
Table of Contents
- $content : string|callable|null
- the content you want to send. Keep it to null if you indicate a filename into $fileName.
- $deleteFileAfterSending : mixed
- Delete file after the upload.
- $doDownload : bool
- Says if the "save as" dialog appear or not to the user.
- $fileName : string
- The path of the file you want to send. Keep empty if you provide the content into $content. Or if $content is a callback, you can indicate the corresponding filename here, to be able to delete it after the output, with $deleteFileAfterSending
- $forcedHttpVersion : bool
- $httpVersion : string
- $mimeType : string
- The mimeType of the current binary file.
- $outputFileName : string
- name of the file under which the content will be sent to the user.
- $_httpHeaders : array<string|int, mixed>
- $_httpHeadersSent : bool
- $_httpStatusCode : string
- $_httpStatusMsg : string
- $_outputOnlyHeaders : bool
- $_type : string
- __construct() : mixed
- constructor.
- addHttpHeader() : mixed
- add an http header to the response.
- cleanCacheHeaders() : mixed
- Clean the differents caches headers.
- clearHttpHeaders() : mixed
- delete all http headers.
- getFormatType() : string
- return the format type name (eg the family type name).
- getHttpHeaders() : mixed
- getType() : string
- return the response type name.
- isValidCache() : bool
- Use the HTTP headers Last-Modified to see if the resource in client cache is fresh.
- output() : bool
- Sends the content or the file to the browser.
- outputErrors() : mixed
- Send a response with a generic error message.
- setContentCallback() : mixed
- Sets the PHP callback associated with this Response.
- setContentGenerator() : mixed
- Sets the PHP callback associated with this Response with an iterable.
- setExpires() : mixed
- Set an expires header to the page/ressource.
- setHttpStatus() : mixed
- set the http status code for the http header.
- setLifetime() : mixed
- Set a life time for the page/ressource.
- _checkRequestType() : mixed
- check if the request is of type GET or HEAD.
- _downloadHeader() : mixed
- set all headers to force download.
- _normalizeDate() : string
- Normalize a date into GMT format.
- sendHttpHeaders() : mixed
- send http headers.
Properties
$content
the content you want to send. Keep it to null if you indicate a filename into $fileName.
public
string|callable|null
$content
Tags
$deleteFileAfterSending
Delete file after the upload.
public
mixed
$deleteFileAfterSending
= \false
Filename is indicated into $fileName
Tags
$doDownload
Says if the "save as" dialog appear or not to the user.
public
bool
$doDownload
= \true
if false, specify the mime type in $mimetype.
Tags
$fileName
The path of the file you want to send. Keep empty if you provide the content into $content. Or if $content is a callback, you can indicate the corresponding filename here, to be able to delete it after the output, with $deleteFileAfterSending
public
string
$fileName
= ''
Tags
$forcedHttpVersion
public
bool
$forcedHttpVersion
= \false
indicate to use the version from $httpVersion
Tags
$httpVersion
public
string
$httpVersion
= '1.1'
the HTTP version to use for the response
Tags
$mimeType
The mimeType of the current binary file.
public
string
$mimeType
= 'application/octet-stream'
It will be sent in the header "Content-Type".
Tags
$outputFileName
name of the file under which the content will be sent to the user.
public
string
$outputFileName
= ''
Tags
$_httpHeaders
protected
array<string|int, mixed>
$_httpHeaders
= array()
list of http headers that will be send to the client
Tags
$_httpHeadersSent
protected
bool
$_httpHeadersSent
= \false
indicates if http headers have already been sent to the client
Tags
$_httpStatusCode
protected
string
$_httpStatusCode
= '200'
the http status code to send
Tags
$_httpStatusMsg
protected
string
$_httpStatusMsg
= 'OK'
the http status message to send
Tags
$_outputOnlyHeaders
protected
bool
$_outputOnlyHeaders
= \false
Should we output only the headers or the entire response
Tags
$_type
protected
string
$_type
= 'binary'
Tags
Methods
__construct()
constructor.
public
__construct() : mixed
Tags
Return values
mixed —addHttpHeader()
add an http header to the response.
public
addHttpHeader(string $htype, string $hcontent[, int $overwrite = true ]) : mixed
will be send during the output of the response.
Parameters
- $htype : string
-
the header type ("Content-Type", "Date-modified"...)
- $hcontent : string
-
value of the header type
- $overwrite : int = true
-
false or 0 if the value should be set only if it doesn't still exist -1 to add the header with the existing values true or 1 to replace the existing header
Tags
Return values
mixed —cleanCacheHeaders()
Clean the differents caches headers.
public
cleanCacheHeaders() : mixed
Tags
Return values
mixed —clearHttpHeaders()
delete all http headers.
public
clearHttpHeaders() : mixed
Tags
Return values
mixed —getFormatType()
return the format type name (eg the family type name).
public
getFormatType() : string
Tags
Return values
string —the name
getHttpHeaders()
public
getHttpHeaders() : mixed
Tags
Return values
mixed —getType()
return the response type name.
public
final getType() : string
Tags
Return values
string —the name
isValidCache()
Use the HTTP headers Last-Modified to see if the resource in client cache is fresh.
public
isValidCache([mixed $dateLastModified = null ][, null|mixed $etag = null ][, bool $cleanCacheHeader = true ]) : bool
Parameters
- $dateLastModified : mixed = null
-
Can be a jDateTime object, a DateTime object or a string understandable by strtotime
- $etag : null|mixed = null
- $cleanCacheHeader : bool = true
-
True for clean/delete other cache headers. Default : true.
Tags
Return values
bool —True if the client resource version is fresh, false otherwise
output()
Sends the content or the file to the browser.
public
output() : bool
Tags
Return values
bool —true if it's ok
outputErrors()
Send a response with a generic error message.
public
outputErrors() : mixed
Tags
Return values
mixed —setContentCallback()
Sets the PHP callback associated with this Response.
public
setContentCallback(callable $callback) : mixed
Parameters
- $callback : callable
-
The callback use to send the content
Tags
Return values
mixed —setContentGenerator()
Sets the PHP callback associated with this Response with an iterable.
public
setContentGenerator(iterable<string|int, mixed> $iterator) : mixed
Parameters
- $iterator : iterable<string|int, mixed>
-
The result of a generator use to build the callback to send the content
Tags
Return values
mixed —setExpires()
Set an expires header to the page/ressource.
public
setExpires(mixed $date[, mixed $cleanCacheHeader = true ]) : mixed
Parameters
- $date : mixed
- $cleanCacheHeader : mixed = true
Tags
Return values
mixed —setHttpStatus()
set the http status code for the http header.
public
setHttpStatus(string $code, string $msg) : mixed
Parameters
- $code : string
-
the status code (200, 404...)
- $msg : string
-
the message following the status code ("OK", "Not Found"..)
Tags
Return values
mixed —setLifetime()
Set a life time for the page/ressource.
public
setLifetime(int $time[, bool $sharedCache = false ][, mixed $cleanCacheHeader = true ]) : mixed
Parameters
- $time : int
-
Time during which the page will be cached. Express in seconds.
- $sharedCache : bool = false
-
True if the lifetime concern a public/shared cache. Default : false.
- $cleanCacheHeader : mixed = true
Tags
Return values
mixed —_checkRequestType()
check if the request is of type GET or HEAD.
protected
_checkRequestType() : mixed
Tags
Return values
mixed —_downloadHeader()
set all headers to force download.
protected
_downloadHeader() : mixed
Tags
Return values
mixed —_normalizeDate()
Normalize a date into GMT format.
protected
_normalizeDate(mixed $date) : string
Parameters
- $date : mixed
-
Can be a jDateTime object, a DateTime object or a string understandable by strtotime
Tags
Return values
string —a date in GMT format
sendHttpHeaders()
send http headers.
protected
sendHttpHeaders() : mixed