ResponseDownload
Trait ResponseDownload.
Tags
Table of Contents
- $request : Request
- $acceptRanges : bool
- $boundary : string
- $byteRanges : array<string|int, mixed>|false
- $delay : int
- $filepath : string
- $filesize : int
- $handle : resource
- $readLength : int
- $sendType : string
- hasDownload() : bool
- Tell if Response has a downloadable file.
- setDownload() : static
- Sets a file to download/stream.
- sendDownload() : void
- flush() : void
- getBoundaryLine() : string
- getContentRangeLine() : string
- getMultiPartTopLine() : string
- parseByteRange() : array<int, array<int, int>>|false
- Parse the HTTP Range Header line.
- prepareRange() : void
- readBuffer() : void
- readFile() : void
- sendMultiPart() : void
- sendSinglePart() : void
- setAcceptRanges() : void
- setMultiPart() : void
- setSinglePart() : void
- validBytePos() : false|int
Properties
$request
public
Request
$request
$acceptRanges
private
bool
$acceptRanges
= true
$boundary
private
string
$boundary
$byteRanges
private
array<string|int, mixed>|false
$byteRanges
= []
$delay
private
int
$delay
= 0
$filepath
private
string
$filepath
$filesize
private
int
$filesize
$handle
private
resource
$handle
$readLength
private
int
$readLength
= 1024
$sendType
private
string
$sendType
= 'normal'
Methods
hasDownload()
Tell if Response has a downloadable file.
public
hasDownload() : bool
Return values
bool —setDownload()
Sets a file to download/stream.
public
setDownload(string $filepath[, bool $inline = false ][, bool $acceptRanges = true ], int $delay[, int $readLength = 1024 ][, string|null $filename = null ]) : static
Parameters
- $filepath : string
- $inline : bool = false
-
Set Content-Disposition header as "inline". Browsers load the file in the window. Set true to allow video or audio streams
- $acceptRanges : bool = true
-
Set Accept-Ranges header to "bytes". Allow partial downloads, media players to move the time position forward and back and download managers to continue/download multi-parts
- $delay : int
-
Delay between flushs in microseconds
- $readLength : int = 1024
-
Bytes read by flush
- $filename : string|null = null
-
A custom filename
Tags
Return values
static —sendDownload()
protected
sendDownload() : void
Return values
void —flush()
private
flush(int $length) : void
Parameters
- $length : int
Return values
void —getBoundaryLine()
private
getBoundaryLine() : string
Return values
string —getContentRangeLine()
private
getContentRangeLine(int $fistByte, int $lastByte) : string
Parameters
- $fistByte : int
- $lastByte : int
Return values
string —getMultiPartTopLine()
private
getMultiPartTopLine() : string
Return values
string —parseByteRange()
Parse the HTTP Range Header line.
private
parseByteRange(string $line) : array<int, array<int, int>>|false
Returns arrays of two indexes, representing first-byte-pos and last-byte-pos. If return false, the Byte Ranges are invalid, so the Response must return a 416 (Range Not Satisfiable) status.
Parameters
- $line : string
Tags
Return values
array<int, array<int, int>>|false —prepareRange()
private
prepareRange(string $rangeLine) : void
Parameters
- $rangeLine : string
Return values
void —readBuffer()
private
readBuffer(int $firstByte, int $lastByte) : void
Parameters
- $firstByte : int
- $lastByte : int
Return values
void —readFile()
private
readFile() : void
Return values
void —sendMultiPart()
private
sendMultiPart() : void
Return values
void —sendSinglePart()
private
sendSinglePart() : void
Return values
void —setAcceptRanges()
private
setAcceptRanges(bool $acceptRanges) : void
Parameters
- $acceptRanges : bool
Return values
void —setMultiPart()
private
setMultiPart(array<int, int> ...$byteRanges) : void
Parameters
- $byteRanges : array<int, int>
Return values
void —setSinglePart()
private
setSinglePart(int $firstByte, int $lastByte) : void
Parameters
- $firstByte : int
- $lastByte : int
Return values
void —validBytePos()
private
validBytePos(string $pos) : false|int
Parameters
- $pos : string