A
A
akula222018-03-19 09:44:28
Yii
akula22, 2018-03-19 09:44:28

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();

I accept so
$res = json_decode(file_get_contents("php://input"));

        file_put_contents('upload/1.txt', print_r($res, 1));

The file is being created, but it is empty
. What could be the reason? How can I take this picture?
ps: I send in the console by cron.
If you remove ->addFile('file', $file) from sending, then the post request normally arrives and is saved

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question