Swoole\Coroutine\Http\Client->addFile

Declaration

<?php
Swoole\Coroutine\Http\Client->addFile(string $path, string $name, string $mimeType = null, string $filename = null, int $offset = 0, int $length = 0)

Parameters

location

The location of the file

name

The file name

mimeType

mimeType

filename

filename

offset

offset

length

length

Return

Description

Attach files for the HTTP request.

Example

<?php
use Swoole\Coroutine\HTTP\Client;

Co\run(function() {
    $cli = new Swoole\Coroutine\Http\Client('httpbin.org', 80);
    $cli->setHeaders([
        'Host' => "httpbin.org"
    ]);
    $cli->set(['timeout' => -1]);
    $cli->addFile(__FILE__, 'file1', 'text/plain');
    $cli->post('/post', ['foo' => 'bar']);
    echo $cli->body;
    $cli->close();
});