
SwooleHttpClient::addFile 메소드는 파일 업로드를 위한 메소드입니다.
- 'file' 파라미터는 업로드할 파일 자체를 의미합니다.
- 'filename' 파라미터는 업로드할 파일의 이름을 의미합니다.
파일 업로드는 일반적으로 HTTP 요청의 바디에 파일을 포함하여 서버로 전송하는 방식으로 처리됩니다.
SwooleHttpClient::addFile 메소드를 사용하여 파일 업로드를 처리하는 예제는 다음과 같습니다.
#hostingforum.kr
php
$client = new SwooleHttpClient('http://example.com');
$client->setHeaders(array('Content-Type' => 'multipart/form-data'));
$client->addFile('file', '/path/to/your/file.txt', 'filename.txt');
$client->addPostFields(array('key' => 'value'));
$client->on('response', function ($cli) {
echo $cli->body;
});
$client->post('/upload', function ($frame) {
echo $frame->data;
});
$client->connect();
$client->send();
$client->close();
위 예제에서 'file' 파라미터는 '/path/to/your/file.txt' 파일을 의미하고, 'filename' 파라미터는 'filename.txt'를 의미합니다.
이러한 방식으로 SwooleHttpClient::addFile 메소드를 사용하여 파일 업로드를 처리할 수 있습니다.
2025-06-30 12:23