Download
in package
Table of Contents
Constants
- STREAM_CHUNK_SIZE = 8192
Methods
- handle() : never
- ファイルをダウンロードまたはインライン配信する。
- buildContentDisposition() : string
- Content-Disposition ヘッダの値を組み立てる。
- clearOutputBuffers() : void
- 出力バッファをすべて破棄する。
- getAttachmentContentType() : string
- 添付配信用の Content-Type を返す(レガシー IE 用の分岐を含む)。
- openStreamOrFail() : array{0: resource, 1: int}
- ストリームを開き、失敗時は 404 を送って終了する。
- parseSingleRange() : array<int, int>|null|false
- 単一の HTTP Range ヘッダーを解析する。
- resolveInlineMime() : string|false
- inline 配信用 MIME type を取得する。
- respondRangeNotSatisfiable() : never
- 416 Range Not Satisfiable を返す。
- sendAttachmentFile() : void
- 添付ファイルとして配信する。
- sendInlineFile() : void
- インライン配信を行う。
- sendNotFound() : never
- 404 Not Found を送信して終了する。
- streamFile() : void
- ファイルポインタから指定バイト数を出力する。
Constants
STREAM_CHUNK_SIZE
private
mixed
STREAM_CHUNK_SIZE
= 8192
Methods
handle()
ファイルをダウンロードまたはインライン配信する。
public
handle(string $path, string $fileName[, string|false $extension = false ][, bool $remove = false ][, Filesystem|null $storage = null ]) : never
$extension を指定した場合は Content-Disposition: inline で返し、 HTTP Range リクエストに対応した部分配信を行う。
このメソッドには、ディレクトリトラバーサル攻撃を防ぐための検証処理は含まれていません。 そのため、利用する際は事前に Storage::validateDirectoryTraversalPath などで、対象パスを必ず検証してください。
Parameters
- $path : string
- $fileName : string
- $extension : string|false = false
-
指定時は inline 配信
- $remove : bool = false
-
配信後にファイルを削除するか
- $storage : Filesystem|null = null
Return values
neverbuildContentDisposition()
Content-Disposition ヘッダの値を組み立てる。
private
buildContentDisposition(string $fileName, string $disposition) : string
Parameters
- $fileName : string
- $disposition : string
-
inline または attachment
Return values
stringclearOutputBuffers()
出力バッファをすべて破棄する。
private
clearOutputBuffers() : void
getAttachmentContentType()
添付配信用の Content-Type を返す(レガシー IE 用の分岐を含む)。
private
getAttachmentContentType() : string
Return values
stringopenStreamOrFail()
ストリームを開き、失敗時は 404 を送って終了する。
private
openStreamOrFail(Filesystem $storage, string $path) : array{0: resource, 1: int}
Parameters
- $storage : Filesystem
- $path : string
Return values
array{0: resource, 1: int}parseSingleRange()
単一の HTTP Range ヘッダーを解析する。
private
parseSingleRange(string $rangeHeader, int $fileSize) : array<int, int>|null|false
戻り値:
- null: Range 指定なし
- array{int,int}: [start, end]
- false: 不正な Range
Parameters
- $rangeHeader : string
- $fileSize : int
Return values
array<int, int>|null|falseresolveInlineMime()
inline 配信用 MIME type を取得する。
private
resolveInlineMime(string $extension) : string|false
Parameters
- $extension : string
Return values
string|falserespondRangeNotSatisfiable()
416 Range Not Satisfiable を返す。
private
respondRangeNotSatisfiable(int $fileSize) : never
Parameters
- $fileSize : int
Return values
neversendAttachmentFile()
添付ファイルとして配信する。
private
sendAttachmentFile(resource $fp, string $fileName, int $fileSize) : void
Parameters
- $fp : resource
- $fileName : string
- $fileSize : int
sendInlineFile()
インライン配信を行う。
private
sendInlineFile(resource $fp, string $fileName, string $extension, int $fileSize) : void
Parameters
- $fp : resource
- $fileName : string
- $extension : string
- $fileSize : int
sendNotFound()
404 Not Found を送信して終了する。
private
sendNotFound() : never
Return values
neverstreamFile()
ファイルポインタから指定バイト数を出力する。
private
streamFile(resource $fp, int $length) : void
Parameters
- $fp : resource
- $length : int