Swoole\Http\Response->sendfile

Declaration

<?php
Swoole\Http\Response->sendfile(string $filename, int $offset = 0, int $length = 0)

Parameters

filename

The file locaiton to be sent. If there is no this file, the sendfile will fail.

offset

The start offset of file to send.

length

The length of data to send. The default value is the whole length of file.

Return

Response

Description

Send a local file directly to HTTP client with sendfile.

Before the call of this method, your have to set content type by $response->header().

Before the call of this method, your must not call $response->write

After the call of this method, $response->end() is called automatically.

$response->sendfile doesn't support gzip compression.

Example

<?php
$response->header('Content-Type', 'image/jpeg');
$response->sendfile(__DIR__.$request->server['request_uri']);