Yii2框架里,如何利用GuzzleHttp上传文件,框架后端接收文件呢?实例如下:

1.GuzzleHttp上传文件代码:

<?php
$filename = '/tmp/1.tar.gz';
$body = [
'timeout' => 5,
'multipart' => [
[
'name' => 'gz',
'contents' => fopen($filename, 'r')
],
],
];
$client = new \GuzzleHttp\Client();
$response = $client->request('post', "http://127.0.0.1/receive", $body);
$json = json_decode($response->getBody());

2.后端接收文件示例(如果要用框架过滤,自己去查):

$name = $_FILES["gz"]['name'];
$type = $_FILES["gz"]['type'];
$tmp = $_FILES["gz"]['tmp_name'];

这三句代码,就获取到文件的基本信息了,怎么处理自己看着办。

Related Posts: Yii2 GuzzleHttp上传文件 接收文件实例 :

avatar