Answer the question
In order to leave comments, you need to log in
How to accept an image sent via yii2-httpclient?
Sending a picture like this
$file = Yii::getAlias('@upload') . "/pic.jpg";
if(file_exists($file)) {
$client = new Client(['baseUrl' => Yii::$app->params['site_api']]);
$response = $client->createRequest()
->setFormat(Client::FORMAT_JSON)
->setMethod('post')
->setUrl('api')
->setData([
'post' => $post,
])
->addFile('file', $file)
->send();
$res = json_decode(file_get_contents("php://input"));
file_put_contents('upload/1.txt', print_r($res, 1));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question